From 9eb0d6fe52fb4adb6cdff761880c400cf90b0cba Mon Sep 17 00:00:00 2001 From: johnny Date: Thu, 5 Jan 2023 11:35:50 +0100 Subject: [PATCH] Ajout de toutes mes fonctions qui marchent dans le Commun, coorection du login et des noms des fonctions avec accents --- Commun.c | 229 ++++++++++++++++++++++++++++++++++++++++++++----------- Jsae.c | 8 +- Jsae.h | 6 +- 3 files changed, 192 insertions(+), 51 deletions(-) diff --git a/Commun.c b/Commun.c index e0c0761..62b8568 100644 --- a/Commun.c +++ b/Commun.c @@ -7,7 +7,7 @@ ListeDept listeDeptNouv(void) return lDept; } -ListeDept insérerEntete(ListeDept lDept,Departement d) +ListeDept insererEntete(ListeDept lDept,Departement d) { MaillonDept *m; m = (MaillonDept *)malloc(sizeof(MaillonDept)); @@ -21,16 +21,16 @@ ListeDept insérerEntete(ListeDept lDept,Departement d) return m; } -ListeDept insérerDept(ListeDept lDept, Departement d) +ListeDept insererDept(ListeDept lDept, Departement d) { if(lDept == NULL) - return insérerEntete(lDept,d); + return insererEntete(lDept,d); if(strcmp(d.dept, lDept->d.dept) < 0) - return insérerEntete(lDept,d); + 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 = insérerDept(lDept->suiv,d); + lDept->suiv = insererDept(lDept->suiv,d); return lDept; } @@ -87,28 +87,6 @@ bool vide(ListeDept lDept) return l->v; }*/ -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; -} - - ListeDept rechercherDept(ListeDept lDept, char dept[], int *trouve) { if(vide(lDept)) @@ -208,11 +186,14 @@ void creerDept(VilleIUT *tiut[],int tLog) } printf("Combien de place y a-t-il pour dans ce département ?\nSaisie : "); scanf("%d%*c", &d.nbP); - printf("\n\n"); + printf("\n"); printf("Quel est le nom du responsable du département ?\nSaisie : "); fgets(d.respAd, 31, stdin); + d.respAd[strlen(d.respAd) - 1] = '\0'; afficherDep(d); - tiut[pos]->lDept = insérerDept(tiut[pos]->lDept, d); + printf("pos : %d\n", pos); + tiut[pos]->lDept = insererDept(tiut[pos]->lDept, d); + afficherVilleDep(*tiut[pos]); return; } @@ -290,7 +271,7 @@ void menuAdmin(VilleIUT *tiut[], int *tLog, int tMax) printf("| 9 Quitter |\n"); printf("|-----------------------------------------------------|\n\n"); printf("Saisie : "); - scanf("%d",&select); + scanf("%d%*c",&select); while(select != 9) { system("clear"); @@ -347,37 +328,26 @@ void menuAdmin(VilleIUT *tiut[], int *tLog, int tMax) printf("| 9 Quitter |\n"); printf("|-----------------------------------------------------|\n\n"); printf("Saisie : "); - scanf("%d",&select); + scanf("%d%*c",&select); } } void menuCandidat(VilleIUT *tiut[], int *tLog, int tMax) { int select = 0; - system("clear"); - printf("_____________________________________________________\n"); - printf("| AFFICHAGE CANDIDAT |\n\n"); - printf("|---------------------------------------------------|"); - printf("| 1 Afficher les villes où il y a un IUT |\n"); - printf("| 2 Afficher tous les départements dans chaque IUT |\n"); - printf("| 3 Nombres de places en première année |\n"); - printf("| 4 Rechercher un département dans les IUT |\n"); - printf("| 9 Quitter |\n"); - printf("|---------------------------------------------------|"); - scanf("%d",&select); while(select != 9) { system("clear"); printf("_____________________________________________________\n"); printf("| AFFICHAGE CANDIDAT |\n\n"); - printf("|---------------------------------------------------|"); + printf("|---------------------------------------------------|\n"); printf("| 1 Afficher les villes où il y a un IUT |\n"); printf("| 2 Afficher tous les départements dans chaque IUT |\n"); printf("| 3 Nombres de places en première année |\n"); printf("| 4 Rechercher un département dans les IUT |\n"); printf("| 9 Quitter |\n"); printf("|---------------------------------------------------|"); - scanf("%d",&select); + scanf("%d%*c",&select); } } @@ -390,3 +360,174 @@ void clearpage(void) scanf("%*c%c", &entre); system("clear"); } + +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; +} + +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 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; +} + +void afficherDep(Departement d) +{ + printf("_____________________________________________________________________________\n"); + printf("| Département |\n"); + printf("|----------------------------------------------------------------------------|\n"); + printf("| %-32s | %3d | %-32s |\n", d.dept, d.nbP, d.respAd); + printf("|----------------------------------------------------------------------------|\n"); +} + +void afficherVille(VilleIUT v) +{ + printf("|----------------------------------|\n"); + printf("| %-32s |\n", v.nom); + printf("|----------------------------------|\n"); +} + +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"); +} + +void afficherVilleDep(VilleIUT v) +{ + ListeDept l; + printf("_________________________________________________________________________________________________________________\n"); + printf("| Ville | Département |\n"); + printf("|----------------------------------|----------------------------------------------------------------------------|\n"); + l = v.lDept; + while(l != NULL) + { + printf("| %-32s | %-32s | %3d | %-32s |\n", v.nom, l->d.dept, l->d.nbP, l->d.respAd); + printf("|----------------------------------|----------------------------------------------------------------------------|\n"); + l = l->suiv; + } +} + +int rechercheIUT(VilleIUT *tiut[], int tLog, char ville[], int *trouve) +{ + int inf,sup,t; + inf = 0; + sup = tLog - 1; + printf("Ville recherchée : %s\n", ville); + 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; +} + + +void globale(void) +{ + int tLog, retour; + VilleIUT *tiut[100]; + if(tiut == NULL) + { + printf("Problème d'allocation mémoire du tableau tiut\n"); + exit(1); + } + tLog = chargement(tiut,100); + if(tLog < 0) + { + printf("Le programme ne peut pas fonctionner\n"); + exit(1); + } + retour = login(); + while(retour != -1) + { + if(retour == 1) + { + menuAdmin(tiut, &tLog, 100); + } + if(retour == 0) + { + menuCandidat(tiut, &tLog, 100); + } + retour = login(); + } +} \ No newline at end of file diff --git a/Jsae.c b/Jsae.c index f6ca1e3..4428801 100644 --- a/Jsae.c +++ b/Jsae.c @@ -26,11 +26,11 @@ int chargement(VilleIUT *tiut[],int tMax) pos = rechercheIUT(tiut,tLog,nomV,&trouve); if(trouve == 1) { - tiut[pos]->lDept = insérerDept(tiut[pos]->lDept, d); + tiut[pos]->lDept = insererDept(tiut[pos]->lDept, d); } else { - insérerVille(tiut, nomV, d, &tLog, tMax, pos); + insererVille(tiut, nomV, d, &tLog, tMax, pos); } fscanf(flot, "%s", nomV); } @@ -47,7 +47,7 @@ Departement lireDep(FILE *flot) return d; } -int insérerVille(VilleIUT *tiut[], char nomV[], Departement d, int *tLog, int tMax, int pos) +int insererVille(VilleIUT *tiut[], char nomV[], Departement d, int *tLog, int tMax, int pos) { int i; if(*tLog == tMax) @@ -65,7 +65,7 @@ int insérerVille(VilleIUT *tiut[], char nomV[], Departement d, int *tLog, int t } strcpy(tiut[pos]->nom, nomV); tiut[pos]->lDept = listeDeptNouv(); - tiut[pos]->lDept = insérerDept(tiut[pos]->lDept,d); + tiut[pos]->lDept = insererDept(tiut[pos]->lDept,d); *tLog = *tLog + 1; return 0; } diff --git a/Jsae.h b/Jsae.h index e8449d2..51b1e29 100644 --- a/Jsae.h +++ b/Jsae.h @@ -25,10 +25,10 @@ typedef struct int chargement(VilleIUT *tiut[],int tMax); Departement lireDep(FILE *flot); -int insérerVille(VilleIUT *tiut[], char nomV[], Departement d, int *tLog, int tMax, int pos); +int insererVille(VilleIUT *tiut[], char nomV[], Departement d, int *tLog, int tMax, int pos); ListeDept listeDeptNouv(void); -ListeDept insérerEntete(ListeDept lDept,Departement d); -ListeDept insérerDept(ListeDept lDept, Departement d); +ListeDept insererEntete(ListeDept lDept,Departement d); +ListeDept insererDept(ListeDept lDept, Departement d); ListeDept supprimerEntete(ListeDept lDept); ListeDept supprimerDept(ListeDept lDept, Departement d); void creerDept(VilleIUT *tiut[],int tLog);