#include #include #include #include"part1.h" void lireM(FILE *f, MaillonDept * m)//lire maillon { fscanf(f, "%s %d", m->departement, &m->nbP); fgets(m->respAd, 31, f); m->respAd[strlen(m->respAd)-1]='\0'; } int Exists(char *st1, char *st2)// servira à trouver si le nom de la ville existe déjà donc il suffira d'ajouter un maillon à la chaîne { if (strcmp(st1,st2)==0) { return 1;//si le nom de la ville existe déjà } } ListDept InsertT(ListDept list, MaillonDept * m)//Insert en tête de la liste { MaillonDept *mins; mins = (MaillonDept*)malloc(sizeof(MaillonDept)); if (mins == NULL){printf("pb malloc"); exit;} strcpy(mins->departement, m->departement); mins->nbP = m->nbP; strcpy(mins->respAd, m->respAd); mins->suiv = list; return mins; } ListDept Insert(ListDept list, MaillonDept *m)//insert globalement { if (list == NULL){return InsertT(list, m);} if (strcmp(list->departement, m->departement)>0){return InsertT(list, m);} list->suiv = Insert(list->suiv, m); return list; } /*étapes pour le chargement: 1) pour chaque ville : malloc VilleIUT ->initialisation à NULL de la liste et fscanf la ville 2) récup le nb pour faire une boucle 3) boucle dans laquelle on crée nb maillons en inserant département dans la liste en triant et on recommence tant que fichier non vide*/ int Chargement(VilleIUT **tV, int tmax, char *nameFile) { FILE *f; int i = 0, cpt; f = fopen(nameFile, "r"); if (f == NULL){printf("pb ouv file"); return -1;} while (!feof(f)) { VilleIUT *v; v = (VilleIUT *)malloc(sizeof(VilleIUT)); if (v == NULL){printf("pb malloc");exit;} fscanf(f, "%s %d", v->ville, &cpt); for (cpt; cpt > 0; cpt--) { MaillonDept *m; m = (MaillonDept*)malloc(sizeof(MaillonDept));//création du maillon if (m == NULL){printf("pb malloc"); exit;} lireM(f, m);//lire le maillon avec la fonction plus haut v->ldept = Insert(v->ldept, m);//insert le maillon à sa bonne place } tV[i] = v; i++; } return i; } void AfficheDpmt ( MaillonDept *dpt )//Affiche un département d'une liste { if ( dpt == NULL) return; printf("%s %d %s \n", dpt->departement, dpt->nbP, dpt->respAd); AfficheDpmt(dpt->suiv); } void afficheIUT (VilleIUT *iut)//Affiche un iut avec ses départements { printf ("%s \n", iut->ville); AfficheDpmt(iut->ldept); } void Affichetableau(VilleIUT ** TabIUT, int n )//Affiche le tableau des iuts avec lerus départements { int i; for ( i = 0 ; i < n ; i++ ) afficheIUT(TabIUT[i]); } ListDept MaJnbP(VilleIUT **tV, char *ville, char dpt, int newnbP) { } ListDept recherche (ListDept l, char *nom ) { if ( l == NULL ){ return l;} if ( strcmp ( l->departement, nom ) == 0) return l; return recherche (l->suiv, nom ); }