From 31f3989a50cc37f1c1cc713ccaa9e51be8626c97 Mon Sep 17 00:00:00 2001 From: Louis LABORIE Date: Fri, 16 Dec 2022 15:23:36 +0100 Subject: [PATCH] 16/12 lalalalalala --- SAEl.c | 264 ++++++++++++++++++++++++++++++++++++-------------------- SAEl.h | 11 ++- iut.txt | 16 ++++ 3 files changed, 195 insertions(+), 96 deletions(-) create mode 100644 iut.txt diff --git a/SAEl.c b/SAEl.c index e276248..1d62c88 100644 --- a/SAEl.c +++ b/SAEl.c @@ -1,127 +1,201 @@ #include "SAEl.h" - -ListeDept creerListeDept(void) { +ListeDept creerListeDept(void) +{ return NULL; -} +} -ListeDept ajouterEnTete(ListeDept l, char* dept, char* nom, int nbP) +VilleIUT **chargementVille(char *nomFich, int tphys, int *tailleL) { - MaillonDept *nouv; - nouv = (MaillonDept *)malloc(sizeof(MaillonDept)); - if (nouv == NULL) + int i = 0, nbDept; + FILE *flot; + VilleIUT **tabV; + tabV = (VilleIUT **)malloc(sizeof(VilleIUT*) * tphys); + if (tabV == NULL) { - printf("Erreur malloc !\n"); + printf("Erreur malloc tab!\n"); exit(1); } - nouv->departement = dept; - nouv->nbPlaces = nbP; - nouv->nom = nom; - nouv->suiv = l; - return nouv; -} - -void ajouterPos(ListeDept l, char* dept, char* nom, int nbP, int pos) -{ - MaillonDept *nouv; - int i = 0; - nouv = (MaillonDept *)malloc(sizeof(MaillonDept)); - if (nouv == NULL) + flot = fopen(nomFich, "r"); + if (flot == NULL) { - printf("Erreur malloc !\n"); + printf("Problème ouverture du fichier !\n"); exit(1); } - while (i != (pos - 1)) + *tailleL = 0; + tabV[*tailleL] = (VilleIUT *)malloc(sizeof(VilleIUT)); + if (tabV[*tailleL] == NULL) { - l = l->suiv; - i += 1; + printf("Erreur malloc ville!\n"); + fclose(flot); + exit(1); } - nouv->suiv = l->suiv; - l->suiv = nouv; - nouv->departement = dept; - nouv->nbPlaces = nbP; - nouv->nom = nom; -} - -void affichageListeDept(ListeDept l) // itératif -{ - while (l != NULL) + *(tabV[*tailleL]) = lireVille(flot); + while (!feof(flot)) { - if (l->suiv == NULL) printf("%d\n",l->x); - else printf("%d => ", l->x); - l = l->suiv; + 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; } -ListeDept inserer(ListeDept l, int x) { // récursif - if (l == NULL) return ajouterEnTête(l,x); - if (x < l->v) return ajouterEnTête(l,x); - if (x == l->v) return l; - l->suiv = inserer(l->suiv,x); - 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; +VilleIUT lireVille(FILE *flot) +{ + VilleIUT v; + fgets(v.ville, 30, flot); + v.ville[strlen(v.ville) - 1] = '\0'; + return v; } - -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); +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; } - -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"); +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); } - return l->v; -} - - -bool vide(ListeDept l) { - if (l == NULL) return true; // 1 - return false; // 0 + strcpy(nouv->departement,dept); + nouv->nbPlaces = nbP; + strcpy(nouv->nom,nom); + nouv->suiv = l; + return nouv; } -int longueur(ListeDept l) { - int cpt = 0; - while (l != NULL) { - cpt + 1; +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; } - return cpt; } -bool recherche(ListeDept l, int x) { - if (l == NULL) return false; - if (x < l->v) return false; - if (x == l->v) return true; - return recherche(l->suiv, x); +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 ajouterEnQueue(ListeDept l, int x) { - if (l == NULL) return ajouterEnTête(l,x); - l->suiv = ajouterEnQueue(l->suiv,x); - return l; -} \ No newline at end of file +// 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, int x) +// { +// if (l == NULL) +// return false; +// if (x < l->v) +// return false; +// if (x == l->v) +// 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; +// } \ No newline at end of file diff --git a/SAEl.h b/SAEl.h index 03e0bc1..063124d 100644 --- a/SAEl.h +++ b/SAEl.h @@ -22,4 +22,13 @@ ListeDept creerListeDept(void); ListeDept ajouterEnTete(ListeDept l, char* dept, char* nom, int nbP); -void ajouterPos(ListeDept l, char* dept, char* nom, int nbP, int pos); \ No newline at end of file +ListeDept inserer(ListeDept l, char *dept, char *nom, int nbP); + +void affichageListeDept(ListeDept l); + +VilleIUT lireVille(FILE *flot); + +ListeDept traiterDept(ListeDept l, FILE *flot); + +VilleIUT** chargementVille(char* nomFich, int tphys, int* tailleL); + diff --git a/iut.txt b/iut.txt new file mode 100644 index 0000000..da41eb7 --- /dev/null +++ b/iut.txt @@ -0,0 +1,16 @@ +Clermont-Ferrand +2 +Informatique +130 +Bouhours Cédric +Réseaux +5 +Unmec Sympa +Lyon +2 +Jeux-videos +24 +Kojima Hideo +GEA +8 +Macron Emmanuel \ No newline at end of file