From 5d7de7c1d71748943f3367c1a24db61f08db6512 Mon Sep 17 00:00:00 2001 From: Nicolas BLONDEAU Date: Fri, 16 Dec 2022 09:50:48 +0100 Subject: [PATCH] =?UTF-8?q?modification=20des=20fichiers,=20mais=20probl?= =?UTF-8?q?=C3=A8me=20chargement,=20=C3=A0=20modifier?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adminIut.c | 3 +- iut.c | 123 ++++++++++++++++++++++++++++++++++++----------------- iut.h | 22 +++++----- testIut.c | 11 +---- ville.don | 11 +++-- 5 files changed, 107 insertions(+), 63 deletions(-) diff --git a/adminIut.c b/adminIut.c index 3b452a4..1efa1be 100644 --- a/adminIut.c +++ b/adminIut.c @@ -2,7 +2,7 @@ #include #include #include "iut.h" - +/* void MenuAdministrateur(VilleIUT V){ char departement[30],respon[30]; int choix,nbp; @@ -65,3 +65,4 @@ void afficherE(Maillon m){ afficherE(m->suivant); } +*/ \ No newline at end of file diff --git a/iut.c b/iut.c index 31bc5d4..2aaa294 100644 --- a/iut.c +++ b/iut.c @@ -3,19 +3,85 @@ #include #include "iut.h" -//Liste: -VilleIUT initialiser (void){ +//Fonction d'initialisation de VilleIUT --> Renvoie une liste vide +VilleIUT Initialisation(void){ VilleIUT V; - V.Idept=NULL; - V.Ville=NULL; + V.ldept = NULL; return V; } +//Fonction qui teste si la liste est vide ou non, et renvoie 'Vrai si la liste est vide', sinon 'Faux' Booleen testVide(VilleIUT V){ - if(V.Ville==NULL) return vrai; + if(V.ville == NULL) + return vrai; return faux; } -VilleIUT Enfiler(VilleIUT V, char *departement, int nbP,char *resp){ + + +int chargement(VilleIUT *tiut[],int tmax){ + int i = 0, j=0; + int nbDep = 0; + VilleIUT V; + MaillonDept *m; + FILE *fe; + fe=fopen("ville.don","r"); + if(fe==NULL){ + printf("Problème d'ouverture du fichier"); + return-1; + } + V = lireVille(fe, &nbDep); + + while(!feof(fe)){ + tiut[i] = (VilleIUT*)malloc(sizeof(VilleIUT)); + if(tiut[i]==NULL){ + printf("Problème de malloc"); + return -3; + } + *tiut[i] = Initialisation(); + *tiut[i] = V; + for(j = 0; j < nbDep; j++){ + *m = lireDep(fe); + tiut[i] = Insertion(m,m->departement, m->nbP, m->resp); + } + V = lireVille(fe, &nbDep); + i++; + } + fclose(fe); + return i; +} + +VilleIUT lireVille(FILE *fe, int *nbDep){ + VilleIUT V; + fscanf(fe,"%s %d", V.ville, nbDep); + return V; +} + +MaillonDept lireDep(FILE *fe){ + MaillonDept m; + fscanf(fe,"%s %d %s", m.departement, &m.nbP, m.resp); + return m; +} + +MaillonDept InsertionTete(MaillonDept *m, char *departement, int nbP,char *resp){ + m = (MaillonDept*)malloc(sizeof(MaillonDept)); + if(m==NULL){ + printf("Problème malloc m"); + exit(1);} + strcpy(m->departement, departement); + m->nbP = nbP; + strcpy(m->resp, resp); + return *m; +} + +MaillonDept Insertion(MaillonDept *m, char *departement, int nbP,char *resp){ + if(m==NULL) + return InsertionTete(m, departement, nbP, resp); + if(strcmp(m->departement, departement)<0) + return InsertionTete(m, departement, nbP, resp); + m->suivant = Insertion(m->suivant, departement, nbP, resp); + return *m; +} +/*VilleIUT Enfiler(VilleIUT V, char *departement, int nbP,char *resp){ MaillonDept *m; m=(MaillonDept*)malloc(sizeof(MaillonDept)); if(m==NULL){printf("pb ouv malloc");exit(1);} @@ -33,6 +99,8 @@ VilleIUT Enfiler(VilleIUT V, char *departement, int nbP,char *resp){ } return V; } + + VilleIUT defiler(VilleIUT V){ MaillonDept *temp; if(testVide(V)){ @@ -61,46 +129,25 @@ void afficher (VilleIUT V){ -int chargeResultat(VilleIUT *tiut[],int taillemax){ - int i=0,m; - FILE *fe; - fe=fopen("ville.don","r"); - if(fe==NULL){printf("pb ouv");return-1;} - VilleIUT V; - V=lireVille(fe); - - while(!feof(fe)){ - if(i==taillemax){ - printf("pb de place"); - return -2; - } - tiut[i]=(VilleIUT*)malloc(sizeof(VilleIUT)); - if(tiut[i]==NULL){ - printf("pb de malloc"); - return -3; - } - *tiut[i]=V; - - i++; - V=lireVille(fe); - } - fclose(fe); - return i; -} -VilleIUT lireVille (FILE *fe){ + +VilleIUT lireVille(FILE *fe, int *nbDep){ VilleIUT V; - fscanf(fe,"%s %s %d %s",&V.ville,&V.Ville->departement,&V.Ville->nbP,&V.Ville->resp); + fscanf(fe,"%s %d", V.ville, nbDep); return V; } -void affichage (VilleIUT *tiut[],int n){ +MaillonDept lireDep(FILE *fe){ + MaillonDept m; + fscanf(fe,"%s %d %s", m.departement, m.nbP, m.resp); + return m; +} + +void affichage (int *tiut[],int n){ int i; for(i=0;iville, tiut[i]->Ville->departement, tiut[i]->Ville->nbP, tiut[i]->Ville->resp); - } - -} \ No newline at end of file +}*/ \ No newline at end of file diff --git a/iut.h b/iut.h index a9477f2..f1209a9 100644 --- a/iut.h +++ b/iut.h @@ -1,19 +1,19 @@ #include +/**/ + typedef struct liste{ char departement[30]; int nbP; char resp[30]; struct liste *suivant; -}MaillonDept,*Maillon; +}MaillonDept, *ListeD; typedef struct{ char ville[30]; - MaillonDept *Ville; - MaillonDept *Idept; + ListeD ldept; }VilleIUT; -//VilleIUT *tiut; typedef enum {faux,vrai}Booleen; @@ -21,25 +21,27 @@ typedef enum {faux,vrai}Booleen; //void MenuUtilisateur(fdhsjklfhdsjklfhdjskl); //Menu administrateur : + /* void MenuAdministrateur(VilleIUT V); Maillon suppression(Maillon m,char *departement,char *responsable); Maillon suppressionTete(Maillon m); void afficherE(Maillon m); - +*/ //recherche //MaillonDept recherche (MaillonDept *Ville,char *departement,char *responsable); //Liste: - VilleIUT initialiser (void); + VilleIUT Initialisation(void); VilleIUT Enfiler(VilleIUT V, char *departement, int nbP,char *resp); Booleen testVide(VilleIUT V); void afficher (VilleIUT V); VilleIUT defiler(VilleIUT V); - - - VilleIUT lireVille (FILE *fe); - int chargeResultat(VilleIUT *tiut[],int taillemax); + VilleIUT lireVille(FILE *fe, int *nbDep); + MaillonDept lireDep(FILE *fe); + int chargeResultat(VilleIUT *tiut[],int tmax); void affichage (VilleIUT *tiut[],int n); + MaillonDept Insertion(MaillonDept *m, char *departement, int nbP,char *resp); + MaillonDept InsertionTete(MaillonDept *m, char *departement, int nbP,char *resp); \ No newline at end of file diff --git a/testIut.c b/testIut.c index 3f4bfbf..9f22635 100644 --- a/testIut.c +++ b/testIut.c @@ -1,21 +1,12 @@ #include #include "iut.h" -VilleIUT Chargement(VilleIUT V){ - V=initialiser(); - - return V; -} - int main(){ VilleIUT V; int n; VilleIUT *tiut[200]; - V = Chargement(V); afficher(V); - - n=chargeResultat(tiut ,200); n=(n+1)/4; printf("%d",n); @@ -29,6 +20,6 @@ int main(){ } if(choix==2){ printf("Menu Administrateur"); - MenuAdministrateur(V); + //MenuAdministrateur(V); } } diff --git a/ville.don b/ville.don index 3c3cad4..6d87e00 100644 --- a/ville.don +++ b/ville.don @@ -1,4 +1,7 @@ -Grenoble Informatique 112 Dupont-Jean -Clermont Informatique 136 Simon-Carine -Aurillac Bio-Info 56 jiji -Clermont Biologie 120 Djojo \ No newline at end of file +Grenoble 1 +Informatique 112 Dupont-Jean +Clermont 2 +Informatique 136 Simon-Carine +Biologie 120 Djojo +Aurillac 1 +Bio-Info 56 jiji \ No newline at end of file