From d250db3917263ccccb0cc54d1a56b9504e6df2c9 Mon Sep 17 00:00:00 2001 From: "Johnny.Ratton" Date: Wed, 14 Dec 2022 21:17:34 +0100 Subject: [PATCH 1/3] Code de chargement, lireDep, afficherDep, afficherVille, globale --- Jsae.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- Jsae.h | 23 ++++++++++++++++++- 2 files changed, 89 insertions(+), 4 deletions(-) diff --git a/Jsae.c b/Jsae.c index d4c21d4..a5e598e 100644 --- a/Jsae.c +++ b/Jsae.c @@ -3,11 +3,75 @@ int chargement(VilleIUT *tiut[],int *tMax) { FILE *flot; - VilleIUT v; + VilleIUT *v; + MaillonDept *m; + int nb = 0, pos; + char trouve; + flot = fopen("IUT.don", "r"); + if(flot == NULL) + { + printf("Problème d'ouverture du fichier\n"); + return -1; + } + while(!feof(flot)) + { + v = (VilleIUT *)malloc(sizeof(VilleIUT)); + if(v == NULL) + { + printf("Problème allocation ville lors de la lecture du fichier\n"); + return -2; + } + fscanf(flot, "%s", v->nom); + pos = recherche(tiut, nb, v->nom, &trouve); + m = (MaillonDept *)malloc(sizeof(MaillonDept)); + if(m == NULL) + { + printf("Problème allocation département lors de la lecture du fichier\n"); + return -3; + } + *m = lireDep(flot); + if(trouve == 'O') + { + insererDep(tiut[pos],*m); + } + else + { + m->suiv = NULL; + v->lDept = m; + tiut[nb] = v; + } + free(v); + free(m); + nb++; + } + return nb; +} + +MaillonDept lireDep(FILE *flot) +{ MaillonDept m; - flot = fopen("") + fscanf(flot,"%s%d", m.dept, &m.nbP); + fgets(m.respAd,31,flot); + m.respAd[strlen(m.respAd) - 1] = '\0'; + return m; +} + +void afficherDep(MaillonDept m) +{ + printf("%s\t%d\t%s\n", m.dept, m.nbP, m.respAd); +} + +void afficherVille(VilleIUT v) +{ + printf("%s\t", v.nom); + while(v.lDept != NULL) + { + afficherDep(*v.lDept); + v.lDept = v.lDept->suiv; + } } + void globale(void) { int tLog, tMax = 10; @@ -19,7 +83,7 @@ void globale(void) exit(1); } tLog = chargement(tiut,&tMax); - if(tLog == -1) + if(tLog < 0) { printf("Le programme ne peut pas fonctionner\n"); exit(1); diff --git a/Jsae.h b/Jsae.h index 0f8310d..2de6796 100644 --- a/Jsae.h +++ b/Jsae.h @@ -1,4 +1,25 @@ #include #include #include -#include \ No newline at end of file +#include + +typedef struct maillonDept +{ + char dept[31]; + int nbP; + char respAd[31]; + struct mailllonDept *suiv; + +}MaillonDept,*ListeDept; + +typedef struct +{ + char nom[31]; + ListeDept *lDept; + +}VilleIUT; + +int chargement(VilleIUT *tiut[],int *tMax); +MaillonDept lireDep(FILE *flot); +void afficherDep(MaillonDept m); +void globale(void); \ No newline at end of file From 0041381fb2ccd72f3be98659a6b4f5b332453824 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20DAIM?= Date: Thu, 15 Dec 2022 08:57:36 +0100 Subject: [PATCH 2/3] =?UTF-8?q?ajout=20de=20la=20fonction=20clearpage/logi?= =?UTF-8?q?n=20fini=20et=20test=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Msae.c | 36 +++++++++++++++++++++++++++++++++--- Msae.h | 3 ++- Mtest.c | 4 +++- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/Msae.c b/Msae.c index 2d959ac..331c85e 100644 --- a/Msae.c +++ b/Msae.c @@ -1,17 +1,47 @@ #include "Msae.h" +void clearpage(void) +{ + char entre; + printf("\nappuyé sur la touche [ENTREE] pour continuer"); + scanf("%*c%c", &entre); + system("clear"); +} + int login(void) { - char id,mdp[31]="mettez20svp"; + int i=3; + char id,mdp[31]="mettez20svp",mdpatrouve[31]; + system("clear"); + printf("################################################################\n\tBienvenue!\n\n\n\tSouhaitez-vous vous connecter en tant qu'utilisateur ou administeur? (U/A)\t"); + scanf("%c%*c",&id); + if(id=='q') + return -1; while(id!='A' && id!='a' && id!='U' && id!='u') { - printf("################################################################\n\tBienvenue!\n\n\n\tSouhaitez-vous vous connecter en tant qu'utilisateur ou administeur? (U/A)\t"); + system("clear"); + printf("################################################################\n\tMauvaise saisie (q pour quitter)\n\n\n\tSouhaitez-vous vous connecter en tant qu'utilisateur ou administeur? (U/A)\t"); scanf("%c%*c",&id); if(id=='q') return -1; } if(id=='A' || id=='a') - return 1; + { + while(i!=0) + { + printf("\n\n\n\tMot de passe :\t"); + fgets(mdpatrouve,31,stdin); + mdpatrouve[strlen(mdpatrouve)-1] = '\0'; + if( strcmp(mdpatrouve,mdp) == 0 ) + return 1; + else + { + i--; + printf("Mot de passe incorrect, il vous reste %d chances\n",i); + } + } + return -1; + } else return 0; system("clear"); } diff --git a/Msae.h b/Msae.h index a1553c5..15eb7c5 100644 --- a/Msae.h +++ b/Msae.h @@ -23,4 +23,5 @@ typedef struct //########## fonction commune ############### int login(void); -void globale(void); \ No newline at end of file +void globale(void); +void clearpage(void); diff --git a/Mtest.c b/Mtest.c index e5e437b..d52874d 100644 --- a/Mtest.c +++ b/Mtest.c @@ -2,6 +2,8 @@ int main(void) { - login(); + int a; + a=login(); + printf("%d\n",a); return 0; } \ No newline at end of file From 6df94b9b75260b5a9b2fdf4717f18644d5a640b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20DAIM?= Date: Thu, 15 Dec 2022 09:08:31 +0100 Subject: [PATCH 3/3] =?UTF-8?q?ajout=20de=20la=20fonction=20clearpage/logi?= =?UTF-8?q?n=20fini=20et=20test=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Msae.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Msae.c b/Msae.c index 331c85e..236b52e 100644 --- a/Msae.c +++ b/Msae.c @@ -30,15 +30,20 @@ int login(void) while(i!=0) { printf("\n\n\n\tMot de passe :\t"); + system("stty -echo"); fgets(mdpatrouve,31,stdin); mdpatrouve[strlen(mdpatrouve)-1] = '\0'; if( strcmp(mdpatrouve,mdp) == 0 ) + { + system("stty echo"); return 1; + } else - { - i--; - printf("Mot de passe incorrect, il vous reste %d chances\n",i); - } + { + i--; + printf("Mot de passe incorrect, il vous reste %d chances\n",i); + } + system("stty echo"); } return -1; }