while (!feof(f_in) || result > 0) { result = fread(buffer,sizeof(Reservation),1,f_in); }
while (!feof(f_in) || result > 0) { result = fread(&laReservation,1,sizeof(Reservation),f_in); }
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <malloc.h> int main(int argc, char * argv[]) { //déclaration typedef struct Reservation { char * nom; char * prenom; char * adresse; int repasAdultes; int repasEnfants; } Reservation; FILE * f_in = NULL; size_t result; Reservation laReservation; //switch switch (argc) { case 1 : fprintf(stderr,"Paramètres manquants\n"); exit(1); case 2 : printf("Ouverture du fichier %s\n",argv[1]); f_in = fopen(argv[1],"r"); break; default : fprintf(stderr,"Trop de paramètre"); exit(1); } printf("1..ok\n"); //si f_in est pas ouvert if(f_in == NULL) { fprintf(stderr,"Erreur d'ouverture des fichiers\n"); exit(1); } printf("2..ok\n"); while (!feof(f_in) || result > 0) { result = fread(&laReservation,sizeof(Reservation),1,f_in); /*printf("Nom : %s\n",laReservation.nom); printf("Prénom : %s\n",laReservation.prenom); printf("Adresse : %s\n",laReservation.adresse); printf("Repas adultes: %i\n",laReservation.repasAdultes); printf("Repas enfants: %i\n",laReservation.repasEnfants);*/ } printf("3..ok\n"); /* while(fgets(laReservation,255,stdin) != NULL) { printf("Nom : %s\n",laReservation.nom); printf("Prénom : %s\n",laReservation.prenom); printf("Adresse : %s\n",laReservation.adresse); printf("Repas adultes: %s\n",laReservation.repasAdultes); printf("Repas enfants: %s\n",laReservation.repasEnfants); } */ fclose(f_in); printf("4..ok\n"); return 0; }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question#include <stdio.h> #include <stdlib.h> #include <string.h> #include <malloc.h> int main(int argc, char * argv[]) { //déclaration typedef struct Reservation { char * nom; char * prenom; char * adresse; int repasAdultes; int repasEnfants; } Reservation; FILE * f_in = NULL; size_t result; Reservation laReservation; //switch switch (argc) { case 1 : fprintf(stderr,"Paramètres manquants\n"); exit(1); case 2 : printf("Ouverture du fichier %s\n",argv[1]); f_in = fopen(argv[1],"r"); break; default : fprintf(stderr,"Trop de paramètre"); exit(1); } printf("1..ok\n"); //si f_in est pas ouvert if(f_in == NULL) { fprintf(stderr,"Erreur d'ouverture des fichiers\n"); exit(1); } printf("2..ok\n"); int i=0; //result = fread(&laReservation,sizeof(Reservation),1,f_in); while (!feof(f_in) || result > 0) { result = fread(&laReservation,sizeof(Reservation),1,f_in); //printf("Nom : %s\n",laReservation.nom); /* printf("Prénom : %s\n",laReservation.prenom); printf("Adresse : %s\n",laReservation.adresse); printf("Repas adultes: %i\n",laReservation.repasAdultes); printf("Repas enfants: %i\n",laReservation.repasEnfants);*/ printf("lecture %d\n",result); i++; } printf("3..ok\n"); fclose(f_in); printf("4..ok\n"); return 0; }
size_t result=1; while (!feof(f_in) && result > 0) { ...