diff --git a/Partie_1/informationsIUT.txt b/Partie_1/informationsIUT.txt index 8b61438..468d925 100755 --- a/Partie_1/informationsIUT.txt +++ b/Partie_1/informationsIUT.txt @@ -1,4 +1,4 @@ Grenoble Informatique 112 Dupont Jean +Clermont-Ferrand Biologie 120 Coralie Elebon Clermont-Ferrand Informatique 136 Simon Carine Aurillac Bio-Informatique 56 Ayoub Milaki -Clermont-Ferrand Biologie 120 Coralie Elebone \ No newline at end of file diff --git a/Partie_1/partie1.c b/Partie_1/partie1.c index f3123cc..92b0d0d 100755 --- a/Partie_1/partie1.c +++ b/Partie_1/partie1.c @@ -26,8 +26,9 @@ int chargementVillesIUT(VilleIUT *tiut[]) while (!feof(file)) { fscanf(file, "%s%s%d", ville, dept, &nbP); + fseek(file, 1, SEEK_CUR); fgets(resp, 30, file); - resp[strlen(resp) -1] = '\0'; + resp[strlen(resp) - 1] = '\0'; insertPos = rechercheVille(tiut, i, ville, &trouve); if (trouve == 0) @@ -68,3 +69,28 @@ int rechercheVille(VilleIUT *tiut[], int nb, char val[], bool *trouve) *trouve = false; return i; } + +void sauvegarde(VilleIUT *tiut[], int nb) +{ + char ville[30], dept[30], resp[30]; + int nbP, posDept; + FILE *file = fopen("informationsIUT.txt", "w"); + if (file == NULL) + { + printf("Fonction sauvegarde : Problème lors de l'ouverture du fichier informationsIUT.txt"); + exit(-1); + } + for (int i = 0; i < nb; i++) + { + strcpy(ville, tiut[i]->ville); + while (!vide(tiut[i]->ldept)) + { + strcpy(dept, getDept(tiut[i]->ldept, 0)); + nbP = getNbP(tiut[i]->ldept, 0); + strcpy(resp, getResp(tiut[i]->ldept, 0)); + fprintf(file, "%s %s %d %s\n", ville, dept, nbP, resp); + tiut[i]->ldept = supprimerEnTete(tiut[i]->ldept); + } + } + fclose(file); +} \ No newline at end of file diff --git a/Partie_1/partie1.h b/Partie_1/partie1.h index 994856d..f4c82b9 100755 --- a/Partie_1/partie1.h +++ b/Partie_1/partie1.h @@ -7,6 +7,7 @@ /* Fichier */ int chargementVillesIUT(VilleIUT *tiut[]); int rechercheVille(VilleIUT *tiut[], int nb, char val[], bool *trouve); +void sauvegarde(VilleIUT *tiut[], int nb); /* Utilisateur */ void affichageVillesIUT(VilleIUT *tiut[], int nb); diff --git a/Partie_1/structures.c b/Partie_1/structures.c index 369c872..bce89f9 100644 --- a/Partie_1/structures.c +++ b/Partie_1/structures.c @@ -154,4 +154,13 @@ void setResp(ListeDept l, int pos, char valeur[]) l = l->suiv; } strcpy(l->resp, valeur); +} + +char* getDept(ListeDept l, int pos) +{ + for (int i = 0; i < pos; i++) + { + l = l->suiv; + } + return l->departement; } \ No newline at end of file diff --git a/Partie_1/structures.h b/Partie_1/structures.h index 6eb1223..c247fe2 100644 --- a/Partie_1/structures.h +++ b/Partie_1/structures.h @@ -29,4 +29,6 @@ ListeDept supprimer(ListeDept l, char departement[]); int getNbP(ListeDept l, int pos); void setNbP(ListeDept l, int pos, int valeur); char* getResp(ListeDept l, int pos); +void setResp(ListeDept l, int pos, char valeur[]); +char* getDept(ListeDept l, int pos); void setResp(ListeDept l, int pos, char valeur[]); \ No newline at end of file diff --git a/Partie_1/test.c b/Partie_1/test.c index 01c0033..c63f1e9 100755 --- a/Partie_1/test.c +++ b/Partie_1/test.c @@ -10,7 +10,8 @@ int main(void) // modificationNbPDept(tiut, nbVilles); // creationDept(tiut, nbVilles); // nbVilles = suppressionDept(tiut, nbVilles); - modificationRespDept(tiut, nbVilles); - affichageDeptIUT(tiut, nbVilles); + //modificationRespDept(tiut, nbVilles); + //affichageDeptIUT(tiut, nbVilles); + sauvegarde(tiut, nbVilles); return 0; }