#include "Jsae.h" int chargement(VilleIUT *tiut[],int tMax) { FILE *flot; int tLog = 0, pos, trouve; char nomV[31]; Departement d; flot = fopen("IUT.don","r"); if(flot == NULL) { printf("Erreur lors de l'ouverture du fichier\n"); fclose(flot); return -1; } fscanf(flot, "%s", nomV); while(!feof(flot)) { if(tLog == tMax) { printf("Tableau tiut plein\n"); fclose(flot); return -3; } d = lireDep(flot); pos = rechercheIUT(tiut,tLog,nomV,&trouve); if(trouve == 1) { tiut[pos]->lDept = insérerDept(tiut[pos]->lDept, d); } else { insérerVille(tiut, nomV, d, &tLog, tMax, pos); } fscanf(flot, "%s", nomV); } fclose(flot); return tLog; } Departement lireDep(FILE *flot) { Departement d; fscanf(flot,"%s%d", d.dept, &d.nbP); fgets(d.respAd,31,flot); d.respAd[strlen(d.respAd) - 1] = '\0'; return d; } int insérerVille(VilleIUT *tiut[], char nomV[], Departement d, int *tLog, int tMax, int pos) { int i; if(*tLog == tMax) { printf("Tableau plein, insertion impossible\n"); return -1; } for(i = *tLog - 1; i >= pos; i--) tiut[i + 1] = tiut[i]; tiut[pos] = (VilleIUT *)malloc(sizeof(VilleIUT)); if(tiut[pos] == NULL) { printf("problème d'allocation mémoire lors de l'insertion de la ville\n"); return -1; } strcpy(tiut[pos]->nom, nomV); tiut[pos]->lDept = listeDeptNouv(); tiut[pos]->lDept = insérerDept(tiut[pos]->lDept,d); *tLog = *tLog + 1; return 0; } void afficherDep(Departement d) { printf("| %-32s\t%3d\t%-32s |\n", d.dept, d.nbP, d.respAd); } void afficherVille(VilleIUT v) { printf("|----------------------------------|\n"); printf("| %-32s |\n", v.nom); printf("|----------------------------------|\n"); } void afficherTIUT(VilleIUT *tiut[], int tLog) { int i = 0; for(i = 0; i < tLog; i++) { afficherVille(*tiut[i]); } printf("\n"); } void afficherVilleDep(VilleIUT *tiut[], int tLog) { MaillonDept *m; int i = 0; for(i = 0; i < tLog; i++) { afficherVille(*tiut[i]); m = tiut[i]->lDept; while(m != NULL) { afficherDep(m->d); m = m->suiv; } } printf("\n"); } int rechercheIUT(VilleIUT *tiut[], int tLog, char ville[], int *trouve) { int inf,sup,t; inf = 0; sup = tLog - 1; printf("Ville recherchée : %s\n", ville); while(inf <= sup) { t = (inf + sup) / 2; if(strcmp(ville, tiut[t]->nom) == 0) { *trouve = 1; return t; } if(strcmp(ville, tiut[t]->nom) < 0) { sup = t - 1; } else { inf = t + 1; } } *trouve = 0; return inf; } void globale(void) { int tLog, retour; VilleIUT *tiut[100]; if(tiut == NULL) { printf("Problème d'allocation mémoire du tableau tiut\n"); exit(1); } tLog = chargement(tiut,100); if(tLog < 0) { printf("Le programme ne peut pas fonctionner\n"); exit(1); } retour = login(); while(retour != -1) { if(retour == 1) { menuAdmin(tiut, &tLog, 100); } if(retour == 0) { menuCandidat(tiut, &tLog, 100); } retour = login(); } }