#include "SAE.h" /* ListeDept chargeListeDept(VilleIUT *tiut[]) { int i = 0; ListeDept liste = listenouv(); FILE *file = fopen("informationsIUT.txt", "r"); while (!feof(file)) { } }*/ int chargementVillesIUT(VilleIUT *tiut[]) { FILE *file = fopen("informationsIUT.txt", "r"); char ville[30], dept[30], resp[30]; int nbP, i = 0, insertPos; bool trouve; if (file == NULL) { printf("Fonction chargementVillesIUT : Problème lors de l'ouverture du fichier informationsIUT.txt"); exit(-1); } 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'; insertPos = rechercheVille(tiut, i, ville, &trouve); if (trouve == 0) { tiut[i] = (VilleIUT *)malloc(sizeof(VilleIUT)); if (tiut[i] == NULL) { printf("Fonction chargementVillesIUT : Problème lors du malloc"); exit(-1); } strcpy(tiut[i]->ville, ville); tiut[i]->ldept = listenouv(); tiut[i]->ldept = inserer(tiut[i]->ldept, dept, nbP, resp); i++; } else { tiut[insertPos]->ldept = inserer(tiut[insertPos]->ldept, dept, nbP, resp); } } fclose(file); return i; } int rechercheVille(VilleIUT *tiut[], int nb, char val[], bool *trouve) { int i; for (i = 0; i < nb; i++) { if (strcmp(tiut[i]->ville, val) == 0) { *trouve = true; return i; } } *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); }