Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include<stdio.h>
#include<myconio.h>
#include<stdlib.h>
struct etudiant
{
char nom[20];
char prenom[20];
int num;
};
//============================================================================
void creerfichier(FILE *f,struct etudiant t[10],int n)
{
int i;
f=fopen("c:\\TD2EX4.txt","w");
if(f==NULL)
{
printf("erreur");
exit(0);
}
 
for(i=0;i<n;i++)
{
printf("entrez le nom de l'etudiant");
scanf("%s",t[i].nom);
printf("entrez le prenom de l'etudiant");
scanf("%s",t[i].prenom);
printf("entrez le n# de l'etudiant");
scanf("%d",&t[i].num);
fprintf(f,"%s %s %d\n",t[i].nom,t[i].prenom,t[i].num);
}
fclose(f);
}
//=============================================================================
void affichagefichier(FILE *f)
{
char nom,prenom;
int num;
f=fopen("c:\\TD2EX4.txt","r");
if(f==NULL)
{
printf("erreur");
exit(0);
}
while(!feof(f))
{
fscanf(f,"%s %s %d\n",nom,prenom,&num);
printf("%s %s %d\n",nom,prenom,num);
}
fclose(f);
}
//=============================================================================
int main()
{
struct etudiant t[10];
int n;
char chemin[]="c:\\TD2EX4.txt";
FILE *f;
printf("entrez le nombre d'etudiant a enregistre: ");
scanf("%d",&n);
creerfichier(f,t,n);
affichagefichier(f);
getch();
return 0;
}
l'execution s'arrete lors du passage a la fonction de l'affichage.
qulqu'en aurait une idee?