From 98a8d4ba38467148c7c70e676f4cb9c7d924a7f1 Mon Sep 17 00:00:00 2001 From: "yann.champeau" Date: Wed, 11 Jan 2023 19:38:47 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20de=20la=20fonction=20saveIUT()=20permet?= =?UTF-8?q?tant=20de=20sauvegarder=20les=20IUTs=20enregistr=C3=A9s=20en=20?= =?UTF-8?q?m=C3=A9moire.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/annexe/saeAnnexe.c | 40 ++++++++++++++++++++++++++++++++++++---- src/annexe/saeAnnexe.h | 6 ++++-- src/saeMain.c | 7 ++++++- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/src/annexe/saeAnnexe.c b/src/annexe/saeAnnexe.c index 1006507..28a3b1d 100644 --- a/src/annexe/saeAnnexe.c +++ b/src/annexe/saeAnnexe.c @@ -13,18 +13,19 @@ void menu(void){ printf("#--------------------------------------------------------------------#\n\n"); printf("Codes pour accéder aux différents profils :\n\n"); printf("C : Consultation.\n"); - printf("A : Administrateur.\n\n"); + printf("A : Administrateur.\n"); + printf("S : Sauvegarder.\n\n"); printf("#--------------------------------------------------------------------#\n\n"); printf("Choisissez votre session : "); } int loadIUT(VilleIUT** tiut){ FILE* f=fopen("Etudiants.bin","rb"); - MaillonDep* m; if(f==NULL){ perror("fopen"); exit(errno); } + MaillonDep* m; int tlogi; fread(&tlogi,sizeof(int),1,f); for(int i=0; iville,sizeof(char),31,f); + } + for(int i=0; ildept); + fwrite(&nbIUTs,sizeof(int),1,f); + m=tiut[i]->ldept; + for(int j=0; jdepartement,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){ if(!lTab){ fprintf(stderr,"Erreur, Pas d'éléments dans le tableau !"); @@ -80,8 +106,14 @@ int existeDep(MaillonDep* liste, char* dep){ return 0; } -int recherche(MaillonDep* liste, char* mot){ - return 1;//A Faire ! +int longueurListe(MaillonDep* liste){ + MaillonDep* m=liste; + int i=0; + while(m!=Null){ + m=m->suivant; + i++; + } + return i; } //Pile diff --git a/src/annexe/saeAnnexe.h b/src/annexe/saeAnnexe.h index 3ea8b4c..d6854fe 100644 --- a/src/annexe/saeAnnexe.h +++ b/src/annexe/saeAnnexe.h @@ -29,7 +29,9 @@ typedef struct file* File; // // // 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); // // @@ -38,7 +40,7 @@ int rechercheTabPtVilleIUT(VilleIUT* tab[],int lTab,char* mot); // //Fonctions relatives aux listes chaînées : --// // int existeDep(MaillonDep* liste, char* dep); // // // // -int recherche(MaillonDep* liste, char* mot); // // +int longueurListe(MaillonDep* liste); // // //--------------------------------------------// // // // diff --git a/src/saeMain.c b/src/saeMain.c index 7e69780..c600770 100644 --- a/src/saeMain.c +++ b/src/saeMain.c @@ -24,7 +24,12 @@ int main(void) reset(); menuAdmin(tiut,tlogi); reset(); + break; + case 'S': + saveIUT(tiut,tlogi); + reset(); } - //save(); + saveIUT(tiut,tlogi); + printf("L'application se ferme ..."); return 0; } \ No newline at end of file