1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| #include <stdio.h>
struct individu{
char nom[20];
char prenom[15]; //Structure Individu qui permet de saisir des infos sur une personne
float taille;
int age;
};
int main(void) {
char nomfich[150];
int NBINDIVIDU;
int i;
FILE * sortie;
printf("Donnez un nom de fichier a creer svp:");
scanf("%20s", nomfich);
printf("Combien d'individus voulez vous stocker dans le fichier?\n");
scanf("%d", &NBINDIVIDU); // Le nombre d'individu que l'on souhaite enregistrer
struct individu fichier[NBINDIVIDU];
sortie=fopen (nomfich, "w");
for (i=0;i<NBINDIVIDU;i++){
printf("Nom :"); scanf("%s", fichier[i].nom); fwrite (&fichier[i].nom, sizeof(int), 1, sortie);
printf("Prenom :"); scanf("%s", fichier[i].prenom); fwrite (&fichier[i].prenom, sizeof(int), 1, sortie);
printf("Taille :"); scanf("%f", &fichier[i].taille); fwrite (&fichier[i].taille, sizeof(int), 1, sortie);
printf("Age :"); scanf("%d", &fichier[i].age); fwrite (&fichier[i].age, sizeof(int), 1, sortie);
}
printf("**** Le fichier a ete creer avec les infos suivantes ****\n");
for (i=0;i<NBINDIVIDU;i++)
printf("Nom:%s Prenom:%s Taille:%f Age:%d\n", fichier[i].nom, fichier[i].prenom, fichier[i].taille, fichier[i].age);
} |
Partager