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 36 37 38
|
#include<stdio.h>
#include<conio.h>
#include<string.h>
typedef struct
{char nom[50];
int nb;
}employe;
int rechercheparnom(char *chemin,char *name)
{FILE *f;employe e;
f=fopen(chemin,"r");
if(!f)
printf("erreur");
else
{
while(!feof(f))
{
fscanf(f,"%s%d",e.nom,&e.nb);
if(strcmp(e.nom,name)==0)
//fclose(f);
return(e.nb);
}
fclose(f);
}
return -1;
}
void main()
{
char nm[50];
char *chemin="c:\\work\\exemple.txt";
printf("donner le nom a comparer");
scanf("%s",nm);
h=rechercheparnom(chemin,nm);
printf("le nombre d'enfant est %d",h);
getch();
} |
Partager