#include "SAEl.h" ListeDept creerListeDept(void) { return NULL; } VilleIUT **chargementVille(char *nomFich, int tphys, int *tailleL) { int i = 0, nbDept; FILE *flot; VilleIUT **tabV; tabV = (VilleIUT **)malloc(sizeof(VilleIUT*) * tphys); if (tabV == NULL) { printf("Erreur malloc tab!\n"); exit(1); } flot = fopen(nomFich, "r"); if (flot == NULL) { printf("Problème ouverture du fichier !\n"); exit(1); } *tailleL = 0; tabV[*tailleL] = (VilleIUT *)malloc(sizeof(VilleIUT)); if (tabV[*tailleL] == NULL) { printf("Erreur malloc ville!\n"); fclose(flot); exit(1); } *(tabV[*tailleL]) = lireVille(flot); while (!feof(flot)) { fscanf(flot, "%d", &nbDept); printf("Nombre de dep : %d\n",nbDept); while (i < nbDept) { tabV[*tailleL]->idDept = creerListeDept(); tabV[*tailleL]->idDept = traiterDept(tabV[*tailleL]->idDept, flot); i += 1; } i = 0; *tailleL += 1; tabV[*tailleL] = (VilleIUT *)malloc(sizeof(VilleIUT)); if (tabV[*tailleL] == NULL) { printf("Erreur malloc ville!\n"); fclose(flot); exit(1); } *(tabV[*tailleL]) = lireVille(flot); } if (tailleL == 0) printf("Fichier vide !\n"); fclose(flot); return tabV; } VilleIUT lireVille(FILE *flot) { VilleIUT v; fgets(v.ville, 30, flot); v.ville[strlen(v.ville) - 1] = '\0'; return v; } ListeDept traiterDept(ListeDept l, FILE *flot) { char nom[30], dept[30]; int nbPlaces; fgets(dept, 30, flot); dept[strlen(dept) - 1] = '\0'; fscanf(flot, "%d", &nbPlaces); fgets(nom, 30, flot); nom[strlen(nom) - 1] = '\0'; l = inserer(l, dept, nom, nbPlaces); return l; } ListeDept ajouterEnTete(ListeDept l, char *dept, char *nom, int nbP) { MaillonDept *nouv; nouv = (MaillonDept *)malloc(sizeof(MaillonDept)); if (nouv == NULL) { printf("Erreur malloc !\n"); exit(1); } strcpy(nouv->departement,dept); nouv->nbPlaces = nbP; strcpy(nouv->nom,nom); nouv->suiv = l; return nouv; } void affichageListeDept(ListeDept l) // itératif { printf("DEPARTEMENT NOMBRE DE PLACES CHEF\n"); while (l != NULL) { printf("%s\t%d\t%s\n", l->departement, l->nbPlaces, l->nom); l = l->suiv; } } ListeDept inserer(ListeDept l, char *dept, char *nom, int nbP) { // récursif if (l == NULL) return ajouterEnTete(l, dept, nom, nbP); if ((strcmp(dept,l->departement)) < 0) return ajouterEnTete(l, dept, nom, nbP); if ((strcmp(dept,l->departement)) == 0) return l; l->suiv = inserer(l->suiv, dept, nom, nbP); return l; } // ListeDept supprimerEnTête(ListeDept l) // { // MaillonDept *aux; // if (l == NULL) // { // printf("suppression interdite\n"); // exit(1); // } // if (l->suiv == NULL) // return NULL; // aux = l; // l = l->suiv; // free(aux); // return l; // } // ListeDept supprimer(ListeDept l, int x) // { // if (l == NULL) // return l; // if (x < l->v) // return l; // si VRAI x ne peut pas se trouver dans la ListeDept // if (l->v == x) // return supprimerEnTête(l); // l->suiv = supprimer(l->suiv, x); // return l; // } // void affichageListeDeptR(ListeDept l) // { // if (l->suiv == NULL) // printf("%d\n", l->v); // printf("%d =>", l->v); // affichageListeDeptR(l->suiv); // } // int tete(ListeDept l) // { // if (l == NULL) // { // printf("opération interdite\n"); // exit(1); // } // return l->v; // } // bool vide(ListeDept l) // { // if (l == NULL) // return true; // 1 // return false; // 0 // } // int longueur(ListeDept l) // { // int cpt = 0; // while (l != NULL) // { // cpt + 1; // l = l->suiv; // } // return cpt; // } bool recherche(ListeDept l, char code[]) { if (l == NULL) return false; if ((strcmp(code,l->departement)) < 0) return false; if (strcmp(code,l->departement)==0) return true; return recherche(l->suiv, x); } // ListeDept ajouterEnQueue(ListeDept l, int x) // { // if (l == NULL) // return ajouterEnTête(l, x); // l->suiv = ajouterEnQueue(l->suiv, x); // return l; // }