# include <stdlib.h>

struct matrice {
  size_t nb_lignes ;
  size_t nb_colonnes ;
  int ** mat ;
};

struct matrice * alloue_matrice ( int n , int m ) {
  struct matrice * mat = malloc ( sizeof ( struct matrice ) ) ;
  int i = 0 ;
  mat -> nb_lignes = n ;
  mat -> nb_colonnes = m ;
  mat -> mat = malloc ( sizeof ( int* ) * n ) ;
  for ( ; i < n ; i++ ) {
    mat -> mat [ i ] = malloc ( sizeof ( int ) * m ) ;
  }
  return mat ;
}

struct matrice * creer_matrice ( int n , int m ) {
  struct matrice * mat = alloue_matrice ( n , m ) ;
  int i = 0 ; int j = 0 ;
  mat -> nb_lignes = n ;
  mat -> nb_colonnes = m ;
  for ( ; i < n ; i++ ){
    j = 0;
    for ( ; j < m ; j++ ) {
      mat -> mat [ i ] [ j ] = rand () % 10 ;
    }
  }
  return mat ;
}

void affiche_matrice ( struct matrice * m ) {
  int x = m -> nb_lignes ;
  int y = m -> nb_colonnes ;
  int i = 0 ; int j = 0 ;
  for ( ; i < x ; i++ ) {
    j = 0;
    for ( ; j < y ; j++ ) {
      printf ( "%d " , m -> mat [ i ] [ j ] ) ;
    }
    printf ("\n");
  }
}

struct matrice * transpose ( struct matrice * mat ) {
  int i = 0 ;
  int j = 0 ;
  struct matrice * mt = alloue_matrice ( mat -> nb_colonnes , mat -> nb_lignes ) ;
  mt -> nb_lignes = mat -> nb_colonnes ;
  mt -> nb_colonnes = mat -> nb_lignes ;
  for ( ; i < mat -> nb_lignes ; i++ ) {
    for( j = 0 ; j < mat -> nb_colonnes ; j++ ) {
      mt -> mat [ j ] [ i ] = mat -> mat [ i ] [ j ] ;
    }
  }
  return mt ;
}

enum symbole { COEUR , CARREAU , PIQUE , TREFLE } ;
enum chiffre { SEPT , HUIT , NEUF , DIX , VALET , DAME , ROI , AS } ;

struct carte {
  enum chiffre valeur ;
  enum symbole couleur ;
};



int main ( int argc , char ** argv ) {
  struct matrice * mat = alloue_matrice ( 4 , 2 ) ;
  srand(time(0));
  mat = creer_matrice ( 4 , 2 ) ;
  affiche_matrice ( mat ) ;
  affiche_matrice ( transpose ( mat ) ) ;
  exit ( 0 ) ;
}

