From e2f13857e08c15796566663beab6e6e9b42dc0c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20DAIM?= Date: Fri, 6 Jan 2023 15:24:55 +0100 Subject: [PATCH] fonctions de mise ajour finies/ marchent pas tres bien --- Msae.c | 184 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- Msae.h | 23 ++++--- Mtest.c | 6 +- 3 files changed, 192 insertions(+), 21 deletions(-) diff --git a/Msae.c b/Msae.c index 08814cd..6e66e77 100644 --- a/Msae.c +++ b/Msae.c @@ -1,12 +1,125 @@ #include "Msae.h" +//################ fonctions listes ################################### +ListeDept listeDeptNouv(void) +{ + ListeDept lDept; + lDept = NULL; + return lDept; +} + +ListeDept insererEntete(ListeDept lDept,Departement d) +{ + MaillonDept *m; + m = (MaillonDept *)malloc(sizeof(MaillonDept)); + if(m == NULL) + { + printf("Problème d'allocation mémoire lors de l'insertion\n"); + exit(1); + } + m->d = d; + m->suiv = lDept; + return m; +} + +ListeDept supprimerEntete(ListeDept lDept) +{ + ListeDept aux; + if(lDept == NULL) + { + printf("Opération interdite\n"); + exit(1); + } + aux = lDept; + lDept = lDept->suiv; + free(aux); + return lDept; +} + +ListeDept supprimerDept(ListeDept lDept, Departement d) +{ + if(lDept == NULL) + return lDept; + if(strcmp(d.dept, lDept->d.dept) < 0) + return lDept; + if(strcmp(d.dept,lDept->d.dept) == 0) + return supprimerEntete(lDept); + lDept->suiv = supprimerDept(lDept->suiv,d); + return lDept; +} + +int longueur(ListeDept lDept) +{ + int compt = 0; + while(lDept != NULL) + { + compt = compt + 1; + lDept = lDept->suiv; + } + return compt; +} + +bool vide(ListeDept lDept) +{ + if(lDept == NULL) + return true; + return false; +} + //################ fonction commune ################################### +Departement lireDep(FILE *flot) +{ + Departement d; + fscanf(flot,"%s%d", d.dept, &d.nbP); + fgets(d.respAd,31,flot); + d.respAd[strlen(d.respAd) - 1] = '\0'; + return d; +} + +int chargement(VilleIUT *tiut[],int tMax) +{ + FILE *flot; + int tLog = 0, pos, trouve; + char nomV[31]; + Departement d; + flot = fopen("IUT.don","r"); + if(flot == NULL) + { + printf("Erreur lors de l'ouverture du fichier\n"); + fclose(flot); + return -1; + } + fscanf(flot, "%s", nomV); + while(!feof(flot)) + { + if(tLog == tMax) + { + printf("Tableau tiut plein\n"); + fclose(flot); + return -3; + } + d = lireDep(flot); + pos = rechercheIUT(tiut,tLog,nomV,&trouve); + if(trouve == 1) + { + tiut[pos]->lDept = insererDept(tiut[pos]->lDept, d); + } + else + { + insererVille(tiut, nomV, d, &tLog, tMax, pos); + } + fscanf(flot, "%s", nomV); + } + fclose(flot); + return tLog; +} + void clearpage(void) { char entre; printf("\nappuyé sur la touche [ENTREE] pour continuer"); - scanf("%*c%c", &entre); + scanf("%c", &entre); system("clear"); } @@ -56,6 +169,26 @@ int login(void) //################# fonctions affichage ########################### +void afficherTIUT(VilleIUT *tiut[], int tLog) +{ + int i = 0; + printf("____________________________________\n"); + printf("| Ville |\n"); + for(i = 0; i < tLog; i++) + { + afficherVille(*tiut[i]); + } + printf("\n"); + clearpage(); +} + +void afficherVille(VilleIUT v) +{ + printf("|----------------------------------|\n"); + printf("| %-32s |\n", v.nom); + printf("|----------------------------------|\n"); +} + void afficherPlace(Departement d) { printf("\nPour ce département il y a %d places en 1ère année \n\n",d.nbP); @@ -85,15 +218,6 @@ void afficherDep(Departement d) printf("|----------------------------------------------------------------------------|\n"); } -//################ fonction liste ###################################### - -bool vide(ListeDept lDept) -{ - if(lDept == NULL) - return true; - return false; -} - //################# fonctions recherche ######################### @@ -139,6 +263,43 @@ ListeDept rechercherDept(ListeDept lDept, char dept[], int *trouve) return rechercherDept(lDept->suiv, dept, trouve); } +//#################### fonctions d'insertion ########################### + +ListeDept insererDept(ListeDept lDept, Departement d) +{ + if(lDept == NULL) + return insererEntete(lDept,d); + if(strcmp(d.dept, lDept->d.dept) < 0) + return insererEntete(lDept,d); + if(strcmp(d.dept,lDept->d.dept) == 0) + printf("Département déjà présent dans cet IUT\n"); + return lDept; + lDept->suiv = insererDept(lDept->suiv,d); + return lDept; +} + +int insererVille(VilleIUT *tiut[], char nomV[], Departement d, int *tLog, int tMax, int pos) +{ + int i; + if(*tLog == tMax) + { + printf("Tableau plein, insertion impossible\n"); + return -1; + } + for(i = *tLog - 1; i >= pos; i--) + tiut[i + 1] = tiut[i]; + tiut[pos] = (VilleIUT *)malloc(sizeof(VilleIUT)); + if(tiut[pos] == NULL) + { + printf("problème d'allocation mémoire lors de l'insertion de la ville\n"); + return -1; + } + strcpy(tiut[pos]->nom, nomV); + tiut[pos]->lDept = listeDeptNouv(); + tiut[pos]->lDept = insererDept(tiut[pos]->lDept,d); + *tLog = *tLog + 1; + return 0; +} //#################### fonction mise à jour ############################ @@ -209,8 +370,9 @@ void miseAJourGlobale(VilleIUT *tiut[], int tLog) char ville[31],dept[31]; MaillonDept *m; Departement d; + system("clear"); printf("Dans quelle ville voulez-vous faire des mises à jour?\t"); - scanf("%s%*c",ville); + scanf("%s",ville); pos=rechercheIUT(tiut,tLog,ville,&trouve); if(trouve!=1) { diff --git a/Msae.h b/Msae.h index cd86a37..5c69588 100644 --- a/Msae.h +++ b/Msae.h @@ -26,6 +26,9 @@ typedef struct }VilleIUT; //########## fonction commune ############### +int chargement(VilleIUT *tiut[],int tMax); +Departement lireDep(FILE *flot); + int login(void); void globale(void); void clearpage(void); @@ -35,6 +38,8 @@ void clearpage(void); void afficherPlace(Departement d); void afficherDep(Departement d); void afficherVilleDep(VilleIUT v); +void afficherTIUT(VilleIUT *tiut[], int tLog); +void afficherVille(VilleIUT v); //########## fonction de mise à jour ########### void miseAJourGlobale(VilleIUT *tiut[], int tLog); @@ -42,18 +47,18 @@ void miseAJourNomDept(Departement d,ListeDept l); void miseAJourResp(Departement d); void miseAJourPlaces(Departement d); +//########## fonctions d'insertion ############## +ListeDept insererDept(ListeDept lDept, Departement d); +int insererVille(VilleIUT *tiut[], char nomV[], Departement d, int *tLog, int tMax, int pos); //########## fonction de recherche ############## ListeDept rechercherDept(ListeDept lDept, char dept[], int *trouve); int rechercheIUT(VilleIUT *tiut[], int tLog, char ville[], int *trouve); //########## fonction liste ############## -ListeDept listenouv(void); -ListeDept InsererEntete(ListeDept l,int nb); -ListeDept Inserer(ListeDept l, int x); -ListeDept supprimerEntete(ListeDept l); -ListeDept supprimer(ListeDept l, int x); -int longueur(ListeDept l); -bool vide(ListeDept l); -ListeDept ajouterEnqueue(ListeDept l, int x); -int tete(ListeDept l); \ No newline at end of file +ListeDept listeDeptNouv(void); +ListeDept insererEntete(ListeDept lDept,Departement d); +ListeDept supprimerEntete(ListeDept lDept); +ListeDept supprimerDept(ListeDept lDept, Departement d); +bool vide(ListeDept lDept); +int longueur(ListeDept lDept); \ No newline at end of file diff --git a/Mtest.c b/Mtest.c index aa6c4fb..c7152d2 100644 --- a/Mtest.c +++ b/Mtest.c @@ -2,6 +2,10 @@ int main(void) { - + int tLog; + VilleIUT *tiut[50]; + tLog=chargement(tiut,50); + afficherTIUT(tiut,tLog); + miseAJourGlobale(tiut,tLog); return 0; }