Bonjour,
voila le problème, je voudrais rechercher dans un fichier le nombre d'etudinats d'une ville et l'afficher.
typedef struct
{
char nom_ville[30];
int population;
int nb_etudiant;
}ville;
printf(" vous etes ici pour lire les informations sur une ville\n");
printf("entrer le nom d'une ville \n");
gets(villemain.nom_ville);
pt=fopen("D:\\ProjetC\\proj.txt","r");
if(pt==NULL)
{
printf("ouverture impossible");
exit(0);
}
while(erreur=fread(&villemain,sizeof(ville),1,pt)!=(feof(pt)))
{
if(erreur==0)
{
return 0;
fclose(pt);
}
if(villemain.nom_ville)
{
printf("la ville est dans le fichier\n\n");
printf("population ou nombre d'etudiants\n");
gets(choix_info);
if(strcmp(choix_info,"nombre d'etudiants")==0)
{
while(fgets(ligne,sizeof(ligne),pt)!=NULL)
{
printf("%s",ligne);
}
while(erreur=fread(&villemain,sizeof(ville),1,pt)!=(feof(pt)))
{
if(erreur==0)
{
return 0;
fclose(pt);
}
printf("%d",villemain.nb_etudiant);
fclose(pt);
}
avec mon fichier texte
NOM DE LA VILLE: paris
POPULATION : 2500000
NOMBRE D'ETUDIANTS : 25000
NOM DE LA VILLE: marseille
NOMBRE D'ETUDIANTS : 15000
le programme m'affiche:
0000
NOMBRE D'ETUDIANTS : 25000
NOM DE LA VILLE: marseille
NOMBRE D'ETUDIANTS : 15000
808792608