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
| int open_file (FILE *f)
{
f=fopen("c:\\exo1","rb");
if (!f)
{ return 1; }
else { return 0; }
}
//**************************************************
void charger_fichier()
{ FILE *f=0;
int i =0;
unsigned int test;
clrscr();
struct etudiants tab1[25];
printf(" ********************* AFFICHAGE DES ETUDIANTS *********************\n\n\n\n");
if(!open_file(f))
{
while(!feof(f))
{ test=fread(&tab1,sizeof(struct etudiants),25,f);
if (test!=0)
{
printf(" matricule %d \n",tab1[i].matr);
printf(" Mr/Mme %s \n",tab1[i].name);
i++;
getch();
}
else { printf(" erreur
la lecture du fichier \n");
getch();
}
}
}
else { printf(" erreur de chargement du fichier ");
getch();
}
fprintf(f," FICHIER DE SAUVEGARDE \n\n");
getch();
fclose(f);
}
//*****************************************************************
int save_bin ()
{
clrscr();
FILE *f;
int i=0;
f=fopen("c:\\exo1","ab");
if (!f)
{ printf(" error file opening \n");
getch();
}
else
{
fwrite(tab,sizeof(struct etudiants),1,f);
i++;
}
fwrite(&t1,sizeof(struct brol),1,f); // sauvegarde du compteur
clrscr();
printf(" \n\n\n Fichier sauvegard .");
fclose(f);
getch();
clrscr();
return 0;
}
// ************************************************ |
Partager