From 9ca06fa72d4ea1fec709e0a48d3e3f629095c890 Mon Sep 17 00:00:00 2001 From: d3friski Date: Fri, 6 Jan 2023 15:35:24 +0100 Subject: [PATCH] chargement et sauvegarde --- source/chargEtSauvFich.c | 26 +++++++++++++++++++++++++- source/result.don | 1 + source/test.c | 2 +- 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 source/result.don diff --git a/source/chargEtSauvFich.c b/source/chargEtSauvFich.c index 93fcc24..4c3c15e 100644 --- a/source/chargEtSauvFich.c +++ b/source/chargEtSauvFich.c @@ -37,7 +37,7 @@ int chargIutDon(VilleIut *tVilleIut[], int nbMax, char nomFich[]) i = i + 1; } if(trouve==1) - ajouterDept(tVilleIut[indice]->lDept, nomDept, resp, nbP); + tVilleIut[indice]->lDept = ajouterDept(tVilleIut[indice]->lDept, nomDept, resp, nbP); fscanf(flot, "%s", nom); lireDep(flot, nomDept, &nbP, resp); } @@ -75,3 +75,27 @@ int appartientIut(VilleIut *tVilleIut[], int nb, char nom[], int *trouve) return i; } +void sauvegarderFichierIutDon(VilleIut *tVilleIut[], int nbVille, char nomFich[]) +{ + FILE *flot; + int i=0; + + flot = fopen(nomFich, "w"); + if(flot==NULL) + { + printf("Probleme lors de l'ouverture du fichier\n"); + exit(1); + } + while(ilDept != NULL) + { + printf("%s %s %d %s", tVilleIut[i]->nom, tVilleIut[i]->lDept->nomDept, tVilleIut[i]->lDept->nbP, tVilleIut[i]->lDept->resp); + fprintf(flot, "%s %s %d %s", tVilleIut[i]->nom, tVilleIut[i]->lDept->nomDept, tVilleIut[i]->lDept->nbP, tVilleIut[i]->lDept->resp); + tVilleIut[i]->lDept = tVilleIut[i]->lDept->suiv; + } + i = i + 1; + } + fclose(flot); +} \ No newline at end of file diff --git a/source/result.don b/source/result.don new file mode 100644 index 0000000..45ebb94 --- /dev/null +++ b/source/result.don @@ -0,0 +1 @@ +Clermont-Ferrand Biologie 120 Perrier Yanic \ No newline at end of file diff --git a/source/test.c b/source/test.c index 30be4f0..2a17a10 100644 --- a/source/test.c +++ b/source/test.c @@ -11,7 +11,6 @@ void testJean(void) VilleIut *tIut[50] ; nbvilles= chargIutDon(tIut, 50, "../donnees/iut.don"); - //tIut = (VilleIut **)malloc(sizeof(VilleIut *)*nbvilles); // strcpy(tIut[0]->nom, "John"); // strcpy(tIut[0]->ldept->nomDept, "Info"); @@ -21,4 +20,5 @@ void testJean(void) afficheVillesIUT(tIut, nbvilles); + sauvegarderFichierIutDon(tIut, nbvilles, "result.don"); }