From 4a58838ccade3ab7b04389485d0d055d02eb6848 Mon Sep 17 00:00:00 2001 From: Louis LABORIE Date: Mon, 9 Jan 2023 13:06:49 +0100 Subject: [PATCH] =?UTF-8?q?Commit=20test=20Sauvegarde=20r=C3=A9ussie?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SAE.c | 7 ++++--- SAEl.c | 37 +++++++++++++++++++++++++++++++++++++ res.txt | 9 +++++++++ testSAE.c | 12 ++++++++++-- 4 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 res.txt diff --git a/SAE.c b/SAE.c index 70a6b8f..5b873a2 100644 --- a/SAE.c +++ b/SAE.c @@ -587,12 +587,13 @@ int longueurListe(ListeDept l) } void SauvegarderIUT(VilleIUT** tabV, int tailleL) { - int i; + int i, nbDept; FILE* flot; - flot = fopen("iut.txt","w"); + flot = fopen("res.txt","w"); for (i = 0 ; i < tailleL ; i++) { fprintf(flot,"%s\n",tabV[i]->ville); - fprintf(flot,"%d\n",longueurListe(tabV[i]->idDept)); + nbDept = longueurListe(tabV[i]->idDept); + fprintf(flot,"%d\n",&nbDept); SauvegarderListe(tabV[i]->idDept,flot); free(tabV[i]); } diff --git a/SAEl.c b/SAEl.c index 46dca53..1bc21b6 100644 --- a/SAEl.c +++ b/SAEl.c @@ -193,6 +193,43 @@ ListeDept rechercheDept(ListeDept l, char code[]) return rechercheDept(l->suiv, code); } +void SauvegarderIUT(VilleIUT** tabV, int tailleL) { + int i, nbDept; + FILE* flot; + flot = fopen("res.txt","w"); + for (i = 0 ; i < tailleL ; i++) { + fprintf(flot,"%s\n",tabV[i]->ville); + nbDept = longueurListe(tabV[i]->idDept); + fprintf(flot,"%d\n",nbDept); + SauvegarderListe(tabV[i]->idDept,flot); + free(tabV[i]); + } +} + +void SauvegarderListe(ListeDept l, FILE* flot) { + MaillonDept* tmp; + while (l->suiv != NULL) { + tmp = l; + fprintf(flot,"%s %d %s\n",l->departement,l->nbPlaces,l->nom); + l = l->suiv; + free(tmp); + } + fprintf(flot,"%s %d %s\n",l->departement,l->nbPlaces,l->nom); + free(l); + +} + +int longueurListe(ListeDept l) +{ + int cpt = 0; + while (l != NULL) + { + cpt += 1; + l = l->suiv; + } + return cpt; +} + /* ListeDept ajouterEnQueue(ListeDept l, int x) { diff --git a/res.txt b/res.txt new file mode 100644 index 0000000..39f300e --- /dev/null +++ b/res.txt @@ -0,0 +1,9 @@ +Clermont-Ferrand +3 +Informatique 130 Bouhours Cédric +Pokemon 7 Sacha Ketchum +Réseaux 5 Unmec Sympa +Lyon +2 +GEA 8 Marx Karl +Jeux-videos 24 Kojima Hideo diff --git a/testSAE.c b/testSAE.c index ee46a11..dba22d4 100644 --- a/testSAE.c +++ b/testSAE.c @@ -2,7 +2,8 @@ void globale(void) { - int tailleL, i; + int tailleL, i, nbP = 7; + char nom[30],depart[30]; VilleIUT** tab; char nomFich[20]; strcpy(nomFich,"iut.txt"); @@ -11,7 +12,14 @@ void globale(void) { printf("Ville : %s\n",tab[i]->ville); affichageListeDept(tab[i]->idDept); } - creationDept(tab,tailleL); + printf("Nom du depart :\n"); + scanf("%s%*c",depart); + printf("Nom responsable :\n"); + fgets(nom,30,stdin); + nom[strlen(nom) - 1] = '\0'; + insererDept(tab[0]->idDept,depart,nom,nbP); + printf("Ville : %s\n",tab[0]->ville); + affichageListeDept(tab[0]->idDept); SauvegarderIUT(tab,tailleL); }