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
| #include<stdio.h>
#include<string.h>
struct etud{char nom[10],pren[10];int moy;}e;
int fet(char [],char []);
main(){
int m,i;
FILE *p; char nom[10],pre[10];
/************** creation de fichier****************/
p=fopen("etudiant.dat","w" );
for(i=0;i<2;++i){
printf("donnez le nom et le prenom et moyenne:\n");
scanf("%s%s%d",e.nom,e.pren,&e.moy);
fwrite(&e,sizeof(struct etud),1,p);}
/***************recherche de l etudint*********************/
printf("donnez le nom et le prenom de l etudiant a consulter :\n");
scanf("%s%s",nom,pre);
m = fet(nom,pre);
printf(" la moyenne de %s %s est %d \n",nom,pre,m);
/**************************************************************/
getch();
return 0;}
/*************fonctin qui reteurne le moyenne***************/
int fet(char n[10],char p[10])
{ FILE *k;
k=fopen("etudiant.dat","r");
while (fread(&e,sizeof(struct etud),1,k),!feof(k))
if(e.nom==n&&e.pren==p)
return e.moy;} |
Partager