bonjour j'ai fait un petit programme avec sauvetage au format binaire mais voila quand je sauve mon fichier il le crée mais ne copie rien dedans voici mon code
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
 
#include <conio.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define maxetu 25
#define maxcotes 3
 
struct etu
{
       int 	mat;
       char 	nom[20];
       float 	cote[maxcotes];
}       tab[maxetu]   ;
 
struct cotes
{
	float	c1;
	float 	c2;
	float 	c3;
}   ;
char	cha='Z';
int	i;
FILE *entree;
//**************************************************************
int  lire_float (char nbf[5])
{
       //	char nbf[5];
	float nbref;
	do {
	gets (nbf);fflush(stdin);
	nbref = atof (nbf);
	}
	while (nbref!=0);
	return (nbref);
}
//**************************************************************
int lire_int(char nbi[5])
{
     //	char 	nbi[5];
	int 	nbrei;
	do {      fflush(stdin);
	gets(nbi);
	nbrei= atoi (nbi);
	}
	while (nbrei!=0);
	return (nbrei);
}
//**************************************************************
 
int lire_mat ( int  m)
{ char 	matt[5];int trouve =0;
/*
for (i=0;i<maxetu ;i++)
	{if ( m == tab[i].mat)
	       {
		printf (" matricule deja utilise \n");
		printf (" entrez un nouveau matricule : \n");
		fflush(stdin);
		gets(matt);tab[i].mat=lire_int(matt);m=tab[i].mat;
	       }
	}    return (m);
       */
	for (i=0;i<maxetu;i++)
	{	if (m==tab[i].mat) trouve =1;
		else trouve = 0;
	}
if (trouve == 0) return 1;
else return 2;
    //		scanf (" %d" , &tab[i].mat );
}
 
//**************************************************************
 
void lire_cotes ( float c)
{
if ((c<0)||(c>20))
 {	printf (" entrez autre cotes :");
	scanf (" %f", &c);}
	else ;
}
 
//*************************************************************
 
void init (etu *tab)    // ou tab[]
{
for (i=0;i<25;i++)
	{strcpy ("null",tab[i].nom) ;
	 for (int j=0;j<3;j++)
	 tab[i].cote[j]=0.0;
	}
}
 
//*************************************************************
 
void rajoute ( etu *tab)
{               clrscr();
	int 	m;
	char 	matric[5], cot [5];
	char 	a[3],b,c;
	int 	j,k,l;
	int 	tmp ;
fflush(stdin);
	printf (" entrez un matricule 0 pour sortir :\n");
	gets (a);
while (a[0]!='0')
{
	tab[i].mat =atoi(a); k=i;
	tmp= atoi(a);
	for  (l=0;l<maxetu && l!=k;l++)
		{ if (tab[l].mat==tmp) {
				      printf ("autre matricule :\n");
				      gets (a);
				      tab[i].mat= atoi (a);
		}                     }
 
 
 printf (" entrez le nom de l'etudiant :\n");
 gets (tab[i].nom);
 for (j=0;j<3;j++)
	{ printf (" entrez la cote nø %d : ",j+1);
	fflush(stdin);
	gets (a); tab[i].cote[j]=atoi (a);
	}
	i++;
 
 do
 {
 fflush(stdin);
 printf (" entrez le matricule de l'etudiant suivant  0 pour sortir :\n");
 gets (a);
 }
 while ((lire_mat(atoi(a))!=1)&&(atoi(a)!=0));
}
}
//***************************************************************
 
void afficher (etu * tab )
{                    clrscr();
for (i=0;i<25 && tab[i].mat!=0;i++)
{
	printf ("%d\t %s\t", tab[i].mat, tab[i].nom );
	for (int j=0;j<maxcotes;j++)
		printf (" %3.1f ", tab[i].cote[j]);
puts (" \n");
}
getch();
}
 
//****************************************************************
void ouverture()
{	etu	tab1[25];
FILE 	*entree;
i=0;
for (int j=0;j<maxetu;j++);
	{
	tab1[j].mat=0;
	strcpy (tab1[j].nom,NULL);
	}
entree = fopen ("c:\\marc", "rb+");
if( !entree)
       {
	puts (" erreur d'ouverture de fichier\n");
	getch();
	}
else
	{
	if (fread (&tab1[i],sizeof(struct etu),25,entree)>0)
	{
		while (i<25 && tab[i].mat!=0 )
 
		{
		if (tab[i].mat!=0)
			{
			printf (" nom : %s\t, matricule : %d\t\n", tab[i].nom,tab[i].mat);
			for (int k=0;k<3;k++)
			printf (" cotes %d : %3.1f\t",k+1,tab[i].cote[k]);
			printf ("\n");
			getch();i++;
			}
		else i++;
		}
	}
	fclose(entree);
}
 getch();
 
 
/*	if ( entree )  puts (" fichier ouvert avec succes !\n");
	else 	       puts (" probleme lors de l'ouverture du fichier \n");
	getch();*/
}
//****************************************************************
void save (etu *tab )
{ //  struct  etu 	p;
//FILE *entree;
entree = fopen ("c:\\marc","rb+");
/*if (entree)
	printf  (" fichier ouvert\n ");
else
	printf (" erreur d'ouverture de fichier\n");
 */
//strcpy( p.nom, nom);p.cote[0]=c1;p.cote[1]=c2;p.cote[2]=c3;p.mat=matri;
fwrite (&tab, sizeof (tab), 1,entree);
fclose(entree);
 
}
 
//*****************************************************************
 
void supprime (int )
{
	int t=0,mt;
	int trouver=0;
	char	m[5];
clrscr();
puts("__________suppression d'un etudiant__________\n");
printf (" entrez le matricule de l'etudiat a supprimer :\n");
	gets(m);  mt=lire_int(m);
while (tab[i].mat!=mt)
{
	t++; i++;trouver=0;
}
	if (tab[i].mat==mt) 	trouver=1;
for (i=t;i<maxetu;i++)
	{
	 tab[i].mat=tab[i+1].mat;
	 strcpy (tab[i].nom, tab[i+1].nom);
	 for (int k=0;k<3;k++)
	 {
		tab[i].cote[k]=tab[i+1].cote[k];
	 }
	}
	if (trouver == 0) puts ("etudiant pas dans le fichier \n");
	else 		  puts (" etudiant supprim‚ ");
}
//*****************************************************************
/*
etu rech_nom (etu *tab)
{
}
 
//*****************************************************************
etu rech_mat(etu *tab)
{         ;
}
//*****************************************************************
void menu_recherche( etu *tab)
{
	char 	ch;
 
clrscr();
puts ("__________menu de recherche__________\n");
puts (" 	recherche (N)ominative\n");
puts (" 	recherche par (M)atricule \n");
puts ("_____________________________________\n");
puts (" 	entrez votre choix :\n");
	ch=getchar ();
	ch=toupper(ch);
switch(ch)
{
	case 'M' : rech_mat(tab) ; break;
	case 'N' : rech_nom(tab) ; break;
}
} */
//*******************************************************************
void menu_fichier()
{
	char	mfc;
clrscr();
puts ("__________menu fichier__________________________\n");
puts ("________________________________________________\n");
puts ("\n");
puts (" 	(O)uverture du fichier\n");
puts ("		(S)auvegarde du fichier( format binaire)\n");
puts ("\n");
puts ("________________________________________________\n");
puts (" 	entrez votre choix\n");
	fflush(stdin);
	mfc = getchar();
	mfc = toupper(mfc);
		       char c[20];
		       int d,e,f,g;
switch (mfc)
{
	case 'O' : ouverture();
	case 'S' : save(tab);
}
}
//*****************************************************************
void menu_etu()
{
	int 	matr;
	char 	c=0;
 
clrscr();
   while (c!='Q')
 
  { clrscr();
  fflush(stdin);
puts ("==========menu principale==========\n");
puts ("___________________________________\n");
puts (" (E)ncoder \n");
puts (" (A)fficher \n");
puts (" (S)upprimer un etudiant \n");
puts (" (O)ption fichier \n");
puts (" Entrez (Q) pour sortir \n");
puts (" menu (R)echerche \n");
puts ("___________________________________\n");
puts (" \n");
puts (" Entrez votre choix : \n");
 
 
	c=toupper(getch ());
switch (c)
{
	case 'E' : rajoute (  tab);break;
	case 'A' : afficher (tab);break;
	case 'O' : menu_fichier();break;
	case 'S' : supprime (matr);break;
     //	case 'R' : menu_recherche(tab);break;
    //	case 'Q' : printf (" fin du programme");break;
}
 
} printf (" fin du programme \n");
 
getch();
}
 
//***************************************************************
 
void main ()
{
clrscr();
//menu_etu(tab);
//cha=getchar();
//while  (cha !='Q');
	 menu_etu ();
 
 
 
}
voila si quelqu'un pouvait me dire quoi ca serait sympa
merci d'avance
marc