bonjour,
voici ma structure:
struct adherents{
int numadherent;
char nom[25];
char prenom[30];
char adresse[80];
char cp[5];
char ville[40];
};
voici mon code pour l'enregistrement d 'un adherent:
struct adherents s;
FILE *pf=NULL;
pf=fopen("adherents","rb");
s.numadherent=0;
if (pf==NULL)
{
pf=fopen("adherents","w+b");
}
else
{
fclose(pf);
pf=fopen("adherents","a+b");
fread(&s,sizeof(s),1,pf);
while(fread(&s,sizeof(s),1,pf),!feof(pf)){}
}
s.numadherent++;
printf("\nNumero de l'adherent : %d\n",s.numadherent);
printf("\nNom:\n");
gets(s.nom);
fflush(stdin);
printf("\nPrenom:\n");
gets(s.prenom);
fflush(stdin);
printf("\nAdresse:\n");
gets(s.adresse);
fflush(stdin);
printf("\nCode postal:\n");
gets(s.cp);
fflush(stdin);
printf("\nVille:\n");
gets(s.ville);
fflush(stdin);
fwrite(&s,sizeof(s),1,pf);
fclose(pf);
printf("\nAdherent enregistre\n");
system("pause");
et voici mon code pour l'affichage des donnees:
printf("\nEntrez le numero d'adherent\n");
int num=0;
scanf("%d",&num);
struct adherents s;
FILE *pf=NULL;
pf=fopen("adherents","rb");
if (pf!=NULL)
{
while (fread(&s,sizeof(s),1,pf),!feof(pf)&& num!=s.numadherent)
{
}
if (feof(pf))
{
printf("Adherent non trouve\n");
}
else
{
printf("Informations sur l'adherent numero %d\n\n",s.numadherent);
printf("\nNom : %s",s.nom);
printf("\nPrenom : %s",s.prenom);
printf("\nAdresse : %s",s.adresse);
printf("\ncode postal : %s",s.cp);
printf("\nVille : %s\n",s.ville);
}
fclose(pf);
}
else
{
printf("Aucun adherent n'est enregistre\n");
}
system("pause");
voila . mon probleme c'est que au lieu de donner comme code postal par exemple : "75011" ca donne "75011paris" (le code postal et la ville). si vous savez d'ou vient le probleme ca m'aiderait beaucoup. Merci d'avance.
Yossi