From 8c7e531a2b4ef9cd68fe8029a235696a169e2a24 Mon Sep 17 00:00:00 2001 From: DahmaneYanis Date: Fri, 13 Jan 2023 17:05:00 +0100 Subject: [PATCH 1/3] =?UTF-8?q?Fonction=20de=20chargement=20termin=C3=A9?= =?UTF-8?q?=20-=20Non=20comment=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/chargEtSauvFich.c | 50 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/source/chargEtSauvFich.c b/source/chargEtSauvFich.c index 43712d3..97483a2 100644 --- a/source/chargEtSauvFich.c +++ b/source/chargEtSauvFich.c @@ -169,6 +169,7 @@ void lectureDep(ListeDept ldept, FILE * fichier) fscanf(fichier, "%s %d ", ldept->nomDept, &ldept->nbP); fgets(ldept->resp, 30, fichier); ldept->resp[strlen(ldept->resp)-1] = '\0'; + ldept->suiv = NULL; } /** @@ -178,14 +179,61 @@ void testCharge(void) { int nbIut, nbMax; VilleIut ** tIut = chargeIutDon("../donnees/iut.don", &nbIut, &nbMax); + fusionIut(tIut, &nbIut); for (int i = 0; i < nbIut; i++) { - printf("[ %s | %s | %d | %s ]\n", tIut[i]->nom, tIut[i]->lDept->nomDept, tIut[i]->lDept->nbP, tIut[i]->lDept->resp); + printf("\nVille : %s\n", tIut[i]->nom); + afficherListe(tIut[i]->lDept); } } +void fusionIut(VilleIut ** tIut, int *nbIut) +{ + int indice; + + for (int i = 0; i < *nbIut; i++) + { + if(existe(tIut[i]->nom, tIut, *nbIut, i, &indice)) + { + fusion(tIut, *nbIut, i, indice); + (*nbIut)--; + i--; + } + } +} +int existe(char * nom, VilleIut ** tIut, int nbIut, int iDepart, int * indice) +{ + for (int i = iDepart+1; i < nbIut; i++) + { + if (strcmp(nom, tIut[i]->nom) == 0) + { + *indice = i; + return 1; + } + } + + return 0; +} + +void fusion(VilleIut ** tIut, int nbIut, int i, int j) +{ + ListeDept aux; + aux = tIut[i]->lDept; + tIut[i]->lDept = tIut[j]->lDept; + tIut[i]->lDept->suiv = aux; + + supprimerIut(tIut, nbIut, j); +} + +void supprimerIut(VilleIut ** tIut, int nbIut, int j) +{ + for (int i = j ; i < nbIut-1 ; i++) + { + tIut[i] = tIut[i+1]; + } +} /*int chargIutDon(VilleIut *tVilleIut[], int nbMax, char nomFich[]) { From 0972ffda5385ee78054bb23f69137568d4f47fdc Mon Sep 17 00:00:00 2001 From: DahmaneYanis Date: Fri, 13 Jan 2023 17:05:47 +0100 Subject: [PATCH 2/3] modif sae.h --- header/sae.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/header/sae.h b/header/sae.h index a11c0c7..51bef55 100644 --- a/header/sae.h +++ b/header/sae.h @@ -169,4 +169,8 @@ VilleIut * initialiseIut(void); VilleIut * lireIut (FILE * fichier); VilleIut ** chargeIutDon(char nomFichier[], int * nbIut, int * nbMax); VilleIut ** initialiseTabIut(void); -void tailleSupTabIut(VilleIut ** tIut, int *nbMax); \ No newline at end of file +void tailleSupTabIut(VilleIut ** tIut, int *nbMax); +void fusionIut(VilleIut ** tIut, int * nbIut); +int existe(char * nom, VilleIut ** tIut, int nbIut, int iDepart, int * indice); +void fusion(VilleIut ** tIut, int nbIut, int i, int j); +void supprimerIut(VilleIut ** tIut, int nbIut, int j); \ No newline at end of file From 12ab40ad39e6049b0c5cf250d94b5210c6e68b93 Mon Sep 17 00:00:00 2001 From: DahmaneYanis Date: Fri, 13 Jan 2023 17:08:40 +0100 Subject: [PATCH 3/3] fonction vitrine --- source/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/main.c b/source/main.c index 08240ef..c9eaef0 100644 --- a/source/main.c +++ b/source/main.c @@ -9,7 +9,7 @@ int main(void) // color // #endif //guillaume(); - //testCharge(); + testCharge(); //Globale(); //testJean(); return 0;