diff --git a/part1.c b/part1.c index 0ed731a..8cb66e8 100644 --- a/part1.c +++ b/part1.c @@ -3,9 +3,106 @@ #include #include"part1.h" -void lireFile(FILE *f, MaillonDept * m) +void lireM(FILE *f, MaillonDept * m)//lire maillon { - fscanf(f, "%s %d %s", m->departement, m->nbP, m->resAd); + 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 insertion du 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; + f = fopen(nameFile, "r"); + if (f == NULL){printf("pb ouv file"); return -1;} + + while (!feof(f)) + { + int cpt; + VilleIUT *v; + v = (VilleIUT *)malloc(sizeof(VilleIUT)); + if (v == NULL){printf("pb malloc");exit;} + fscanf(f, "%s %d", v->ville, &cpt); + printf("**%d**\n", cpt); + for (cpt; cpt > 0; cpt--) + { + printf("bleu\n"); + MaillonDept *m; + m = (MaillonDept*)malloc(sizeof(MaillonDept)); + if (m == NULL){printf("pb malloc"); exit;} + lireM(f, m); + AfficheDpmt(m); + v->ldept = Insert(v->ldept, m); + } + tV[i] = v; + i++; + } + return i; + + +} + + +void AfficheDpmt ( MaillonDept *dpt ){ + if ( dpt == NULL) return; + printf("%s %d %s \n", dpt->departement, dpt->nbP, dpt->respAd); + AfficheDpmt(dpt->suiv);} + + + +void afficheIUT (VilleIUT *iut){ + printf ("%s \n", iut->ville); + AfficheDpmt(iut->ldept); +} + + + +void Affichetableau(VilleIUT ** TabIUT, int n ){ + int i; + + for ( i = 0 ; i < n ; i++ ) + afficheIUT(TabIUT[i]); } diff --git a/prout.don b/part1.don similarity index 98% rename from prout.don rename to part1.don index 14578de..45776df 100644 --- a/prout.don +++ b/part1.don @@ -10,8 +10,3 @@ Biologie 154 Jean Claude Aurillac 2 Biologie 102 Michèle Robert Bio-Informatique 98 Claude Loeb - - - - - diff --git a/part1.h b/part1.h index d11ffb7..dd1e45e 100644 --- a/part1.h +++ b/part1.h @@ -7,7 +7,7 @@ typedef struct list{ char departement[31];//le nom du département int nbP;//nombre de places char respAd[31];//nom du responsable - stuct list * suiv;//pointeur suivant de la liste + struct list * suiv;//pointeur suivant de la liste }MaillonDept; @@ -15,3 +15,14 @@ typedef struct{ char ville[30];//nom de la ville MaillonDept * ldept;//liste de départements }VilleIUT; + +typedef MaillonDept * ListDept; + +void lireM(FILE *f, MaillonDept * m);//lire maillon +int Exists(char *st1, char *st2); +ListDept InsertT(ListDept list, MaillonDept * m); +ListDept Insert(ListDept list, MaillonDept *m); +int Chargement(VilleIUT **tV, int tmax, char *nameFile); +void AfficheDpmt ( MaillonDept *dpt ); +void afficheIUT (VilleIUT *iut); +void Affichetableau(VilleIUT ** TabIUT, int n ); diff --git a/test b/test index 7ef8ad3..a96f7a1 100755 Binary files a/test and b/test differ diff --git a/tpart1.c b/tpart1.c index 82b3b9a..bda1319 100644 --- a/tpart1.c +++ b/tpart1.c @@ -6,44 +6,11 @@ - - - - - - - - - - - - - - - - - - - - - -void AfficheDpmt ( MaillonDept *dpt ){ - if ( dpt == NULL) return; - printf("%s %d %s ", dpt.departement, dpt.nbP, dpt.respAd); - AfficheDpmt(dpt->suiv);} - - - -void afficheIUT (VilleIUT *iut){ - printf ("%s ", iut->ville); - AfficheDpmt(iut->ldept); +int main(void) +{ + VilleIUT *tV[200]; + int nb; + nb = Chargement(tV, 200, "part1.don"); + Affichetableau(tV, nb); + return 0; } - - - -void Affichetableau(VilleIUT * TabIUT, int n ){ - int i; - - for ( i = 0 ; i < n ; i++ ) - afficheIUT(TabIUT[i]); -} \ No newline at end of file