1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| struct stLivre
{
char titre_livre[20] ;
int cote ;
float prix ;
} ;
struct stLivre *tableau = NULL ;
// Allouer N structures de type livre
tableau = (struct stLivre*)malloc(N*sizeof(struct stLivre)) ;
if(tableau==NULL) {
printf("Pas assez de mémoire\n") ;
return EXIT_FAILURE ;
}
...
// Initialisation de la première "case"
strncpy(&tableau[0].titre_livre, "Le langage C", 20) ;
tableau[0].cote = 5 ;
tableau[0].prix = 32.90 ;
...
// Libération de la mémoire
free(tableau) ;
... |
Partager