From 8c7e531a2b4ef9cd68fe8029a235696a169e2a24 Mon Sep 17 00:00:00 2001 From: DahmaneYanis Date: Fri, 13 Jan 2023 17:05:00 +0100 Subject: [PATCH] =?UTF-8?q?Fonction=20de=20chargement=20termin=C3=A9=20-?= =?UTF-8?q?=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[]) {