From afbeb3a4a88b52159f599eb99ccab648e647ec26 Mon Sep 17 00:00:00 2001 From: "Johnny.Ratton" Date: Thu, 15 Dec 2022 15:48:21 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20de=20la=20fontcion=20reallocation=20pou?= =?UTF-8?q?r=20augmenter=20la=20taille=20du=20tableau.=20D=C3=A9buggage=20?= =?UTF-8?q?du=20code,=20tout=20compile=20mais=20pour=20l'instant=20les=20f?= =?UTF-8?q?onctions=20ne=20marchent=20pas.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Jsae.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- Jtest.c | 8 +++++- 2 files changed, 89 insertions(+), 7 deletions(-) diff --git a/Jsae.c b/Jsae.c index 13cdaae..89de2fb 100644 --- a/Jsae.c +++ b/Jsae.c @@ -5,8 +5,7 @@ int chargement(VilleIUT *tiut[],int *tMax) FILE *flot; VilleIUT *v; MaillonDept *m; - int nb = 0, pos; - char trouve; + int nb = 0, pos, trouve; flot = fopen("IUT.don", "r"); if(flot == NULL) { @@ -16,6 +15,10 @@ int chargement(VilleIUT *tiut[],int *tMax) } while(!feof(flot)) { + if(nb == *tMax) + { + tiut = reallocation(tiut,tMax); + } v = (VilleIUT *)malloc(sizeof(VilleIUT)); if(v == NULL) { @@ -24,6 +27,7 @@ int chargement(VilleIUT *tiut[],int *tMax) return -2; } fscanf(flot, "%s", v->nom); + printf("Nom de la ville : %s\n", v->nom); pos = rechercheIUT(tiut, nb, v->nom, &trouve); m = (MaillonDept *)malloc(sizeof(MaillonDept)); if(m == NULL) @@ -33,19 +37,19 @@ int chargement(VilleIUT *tiut[],int *tMax) return -3; } *m = lireDep(flot); - if(trouve == 'O') + if(trouve == 1) { - insererDep(tiut[pos],*m); + insererDept(*(tiut[pos]), m); } else { m->suiv = NULL; v->lDept = m; tiut[nb] = v; + nb++; } free(v); free(m); - nb++; } return nb; } @@ -56,6 +60,7 @@ MaillonDept lireDep(FILE *flot) fscanf(flot,"%s%d", m.dept, &m.nbP); fgets(m.respAd,31,flot); m.respAd[strlen(m.respAd) - 1] = '\0'; + afficherDep(m); return m; } @@ -69,7 +74,7 @@ void afficherVille(VilleIUT v) printf("%s", v.nom); while(v.lDept != NULL) { - afficherDep(*v.lDept); + afficherDep(*(v.lDept)); v.lDept = v.lDept->suiv; } } @@ -83,6 +88,76 @@ void afficherTIUT(VilleIUT *tiut[], int tLog) } } +int rechercheIUT(VilleIUT *tiut[], int tLog, char ville[], int *trouve) +{ + int inf,sup,t; + inf = 0; + sup = tLog - 1; + while(inf <= sup) + { + t = (inf + sup) / 2; + if(strcmp(ville, tiut[t]->nom) == 0) + { + *trouve = 1; + return t; + } + if(strcmp(ville, tiut[t]->nom) < 0) + { + sup = t - 1; + } + else + { + inf = t + 1; + } + } + *trouve = 0; + return inf; +} + +int insererDept(VilleIUT v, MaillonDept *m) +{ + int trouve; + MaillonDept *pos; + pos = rechercheDept(v.lDept,&trouve,m->dept); + printf("Valeur de trouve : %d", trouve); + if(trouve == 1) + { + printf("\nDépartement déjà présent dans cet IUT\n"); + return -1; + } + m->suiv = pos; + pos = m; + return 1; +} + +MaillonDept* rechercheDept(ListeDept lDept, int *trouve, char nom[]) +{ + while(lDept->suiv != NULL) + { + if(strcmp(nom,lDept->dept) == 0) + { + *trouve = 1; + return lDept; + } + if(strcmp(nom,lDept->dept) < 0) + { + *trouve=0; + return lDept; + } + lDept = lDept->suiv; + } + *trouve = 0; + return lDept; +} + +VilleIUT** reallocation(VilleIUT *tiut[], int *tMax) +{ + VilleIUT **aux; + aux = (VilleIUT **)realloc(tiut, (sizeof(VilleIUT *) * (*tMax)) + 5); + *tMax = *tMax + 5; + return aux; +} + void globale(void) { int tLog, tMax = 10; @@ -99,4 +174,5 @@ void globale(void) printf("Le programme ne peut pas fonctionner\n"); exit(1); } + afficherTIUT(tiut, tLog); } \ No newline at end of file diff --git a/Jtest.c b/Jtest.c index 37d15c5..509e66c 100644 --- a/Jtest.c +++ b/Jtest.c @@ -1 +1,7 @@ -#include "Jsae.h" \ No newline at end of file +#include "Jsae.h" + +int main(void) +{ + globale(); + return 0; +} \ No newline at end of file