#include #include #include #include "iut.h" //Fonction d'initialisation de VilleIUT --> Renvoie une liste vide VilleIUT Initialisation(void){ VilleIUT V; V.ldept = NULL; return V; } //Fonction qui teste si la liste est vide ou non, et renvoie 'Vrai si la liste est vide', sinon 'Faux' Booleen testVide(VilleIUT V){ if(V.ville == NULL) return vrai; return faux; } int chargement(VilleIUT *tiut[],int tmax){ int i = 0, j=0; int nbDep = 0; VilleIUT V; MaillonDept *m; FILE *fe; fe=fopen("ville.don","r"); if(fe==NULL){ printf("Problème d'ouverture du fichier"); return-1; } V = lireVille(fe, &nbDep); while(!feof(fe)){ tiut[i] = (VilleIUT*)malloc(sizeof(VilleIUT)); if(tiut[i]==NULL){ printf("Problème de malloc"); return -3; } *tiut[i] = Initialisation(); *tiut[i] = V; for(j = 0; j < nbDep; j++){ *m = lireDep(fe); tiut[i] = Insertion(m,m->departement, m->nbP, m->resp); } V = lireVille(fe, &nbDep); i++; } fclose(fe); return i; } VilleIUT lireVille(FILE *fe, int *nbDep){ VilleIUT V; fscanf(fe,"%s %d", V.ville, nbDep); return V; } MaillonDept lireDep(FILE *fe){ MaillonDept m; fscanf(fe,"%s %d %s", m.departement, &m.nbP, m.resp); return m; } MaillonDept InsertionTete(MaillonDept *m, char *departement, int nbP,char *resp){ m = (MaillonDept*)malloc(sizeof(MaillonDept)); if(m==NULL){ printf("Problème malloc m"); exit(1);} strcpy(m->departement, departement); m->nbP = nbP; strcpy(m->resp, resp); return *m; } MaillonDept Insertion(MaillonDept *m, char *departement, int nbP,char *resp){ if(m==NULL) return InsertionTete(m, departement, nbP, resp); if(strcmp(m->departement, departement)<0) return InsertionTete(m, departement, nbP, resp); m->suivant = Insertion(m->suivant, departement, nbP, resp); return *m; } /*VilleIUT Enfiler(VilleIUT V, char *departement, int nbP,char *resp){ MaillonDept *m; m=(MaillonDept*)malloc(sizeof(MaillonDept)); if(m==NULL){printf("pb ouv malloc");exit(1);} strcpy(m->departement, departement); m->nbP=nbP; strcpy(m->resp,resp); m->suivant=NULL; if(testVide(V)){ V.Ville=m; V.Idept=m; } else{ V.Idept->suivant=m; V.Idept=m; } return V; } VilleIUT defiler(VilleIUT V){ MaillonDept *temp; if(testVide(V)){ printf("testVide"); return V; } temp=V.Ville; V.Ville=temp->suivant; free(temp); if(V.Ville==NULL) V.Idept=NULL; return V; } void afficher (VilleIUT V){ if(testVide(V)) return; printf("\n%s\t",V.Ville->departement); printf("%d\t",V.Ville->nbP); printf("%s\t",V.Ville->resp); V.Ville=V.Ville->suivant; afficher(V); } VilleIUT lireVille(FILE *fe, int *nbDep){ VilleIUT V; fscanf(fe,"%s %d", V.ville, nbDep); return V; } MaillonDept lireDep(FILE *fe){ MaillonDept m; fscanf(fe,"%s %d %s", m.departement, m.nbP, m.resp); return m; } void affichage (int *tiut[],int n){ int i; for(i=0;iville, tiut[i]->Ville->departement, tiut[i]->Ville->nbP, tiut[i]->Ville->resp); } }*/