Ajout de la fonction saveIUT() permettant de sauvegarder les IUTs enregistrés en mémoire.

master
Yann CHAMPEAU 3 years ago
parent 4a3855a624
commit 98a8d4ba38

@ -13,18 +13,19 @@ void menu(void){
printf("#--------------------------------------------------------------------#\n\n"); printf("#--------------------------------------------------------------------#\n\n");
printf("Codes pour accéder aux différents profils :\n\n"); printf("Codes pour accéder aux différents profils :\n\n");
printf("C : Consultation.\n"); printf("C : Consultation.\n");
printf("A : Administrateur.\n\n"); printf("A : Administrateur.\n");
printf("S : Sauvegarder.\n\n");
printf("#--------------------------------------------------------------------#\n\n"); printf("#--------------------------------------------------------------------#\n\n");
printf("Choisissez votre session : "); printf("Choisissez votre session : ");
} }
int loadIUT(VilleIUT** tiut){ int loadIUT(VilleIUT** tiut){
FILE* f=fopen("Etudiants.bin","rb"); FILE* f=fopen("Etudiants.bin","rb");
MaillonDep* m;
if(f==NULL){ if(f==NULL){
perror("fopen"); perror("fopen");
exit(errno); exit(errno);
} }
MaillonDep* m;
int tlogi; int tlogi;
fread(&tlogi,sizeof(int),1,f); fread(&tlogi,sizeof(int),1,f);
for(int i=0; i<tlogi; i++){ for(int i=0; i<tlogi; i++){
@ -58,6 +59,31 @@ int loadIUT(VilleIUT** tiut){
return tlogi; return tlogi;
} }
void saveIUT(VilleIUT** tiut, int tlogi){
FILE* f=fopen("Etudiants.bin","rb");
if(f==NULL){
perror("fopen");
exit(errno);
}
MaillonDep* m;
fwrite(&tlogi,sizeof(int),1,f)
for(int i=0; i<tlogi; i++){
fwrite(tiut[i]->ville,sizeof(char),31,f);
}
for(int i=0; i<tlogi; i++){
int nbIUTs=longueurListe(tiut[i]->ldept);
fwrite(&nbIUTs,sizeof(int),1,f);
m=tiut[i]->ldept;
for(int j=0; j<nbIUTs; j++){
fwrite(m->departement,sizeof(char),31,f);
fwrite(&m->nbp,sizeof(int),1,f);
fwrite(m->resp,sizeof(char),51,f);
m=m->suivant;
}
}
printf("Les IUTs enregistrés ont bien étés sauvegardés.");
}
int rechercheTabPtVilleIUT(VilleIUT* tab[],int lTab,char* mot){ int rechercheTabPtVilleIUT(VilleIUT* tab[],int lTab,char* mot){
if(!lTab){ if(!lTab){
fprintf(stderr,"Erreur, Pas d'éléments dans le tableau !"); fprintf(stderr,"Erreur, Pas d'éléments dans le tableau !");
@ -80,8 +106,14 @@ int existeDep(MaillonDep* liste, char* dep){
return 0; return 0;
} }
int recherche(MaillonDep* liste, char* mot){ int longueurListe(MaillonDep* liste){
return 1;//A Faire ! MaillonDep* m=liste;
int i=0;
while(m!=Null){
m=m->suivant;
i++;
}
return i;
} }
//Pile //Pile

@ -29,7 +29,9 @@ typedef struct file* File; // //
// //
void menu(void); // void menu(void); //
// //
int loadIUT(VilleIUT** tiut); //Fichier Binaire. // int loadIUT(VilleIUT** tiut); //
//
void saveIUT(VilleIUT** tiut, int tlogi); //
// //
int rechercheTabPtVilleIUT(VilleIUT* tab[],int lTab,char* mot); // int rechercheTabPtVilleIUT(VilleIUT* tab[],int lTab,char* mot); //
// //
@ -38,7 +40,7 @@ int rechercheTabPtVilleIUT(VilleIUT* tab[],int lTab,char* mot); //
//Fonctions relatives aux listes chaînées : --// // //Fonctions relatives aux listes chaînées : --// //
int existeDep(MaillonDep* liste, char* dep); // // int existeDep(MaillonDep* liste, char* dep); // //
// // // //
int recherche(MaillonDep* liste, char* mot); // // int longueurListe(MaillonDep* liste); // //
//--------------------------------------------// // //--------------------------------------------// //
// //
// //

@ -24,7 +24,12 @@ int main(void)
reset(); reset();
menuAdmin(tiut,tlogi); menuAdmin(tiut,tlogi);
reset(); reset();
break;
case 'S':
saveIUT(tiut,tlogi);
reset();
} }
//save(); saveIUT(tiut,tlogi);
printf("L'application se ferme ...");
return 0; return 0;
} }
Loading…
Cancel
Save