From 55add53f3daddc87aacf89e57fa204545027e3f3 Mon Sep 17 00:00:00 2001 From: Lola CHALMIN Date: Mon, 9 Jan 2023 11:57:52 +0100 Subject: [PATCH] =?UTF-8?q?euh=20=C3=A7a=20m'=C3=A9nerve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- part4.c | 202 +++++++++++++++++++++++++++++++++----------------------- part4.h | 11 +-- 2 files changed, 127 insertions(+), 86 deletions(-) diff --git a/part4.c b/part4.c index 8b8bf2e..c0eb9f7 100644 --- a/part4.c +++ b/part4.c @@ -32,21 +32,33 @@ int testVideChx (Filechx f){// fonction test si la Filechx est vide return 1 sin Candidat lireCa(FILE *fe)// lit un candidat dans un fichier { Candidat c;//candidat que l'on retournera - Choix chx;//pour la création de maillons - int cpt = 0;//qui servira à compter le nombre de choix - fscanf(fe,"%d", c.nEtu); - fgets(c.nom, 23, fe); - c.nom[strlen(c.nom)-1]= '\0'; - fgets(c.prenom, 23, fe); - c.prenom[strlen(c.prenom)-1]= '\0'; - fscanf(fe, "%f %f %f %f %d%*c", c.moymat, c.moyfr, c.moyen, c.moyspe, c.nbchx); - c.lchx = init();//initialisation de la liste + int cpt;//pour la création de maillons + fscanf(fe,"%*c%d", &c.nEtu); + fscanf(fe, "%s", c.nom); + + fscanf(fe, "%s", c.prenom); + //fgets(c.prenom, 27, fe); + //c.prenom[strlen(c.prenom)-1]= '\0'; + printf("%s\n", c.prenom); + fscanf(fe, "%f %f %f %f", &c.moymat, &c.moyfr, &c.moyen, &c.moyspe); + fscanf(fe, "%d", &c.nbchx); + printf("%d", c.nbchx); + c.fchx = initchx();//initialisation de la file + for (cpt = 0; cpt < c.nbchx; cpt++) + { + //puts("je passe ici aussi\n"); + Choix chx; + chx = lireC(fe); + c.fchx = enf(c.fchx, chx); + } return c; } + +/* // FAIRE LECTURE CHOIX POUR METTRE EN PARAMETRE PLUTOT QUE LE FE -Filechx enfilechx ( Filechx f , File *fe){//fonction enfile un maillon choix en fin de file Choix +Filechx enfilechx ( Filechx f , FILE *fe){//fonction enfile un maillon choix en fin de file Choix Maillonchx *mch; int nbchoix, i, nbcand, numCand; char nom[30], prenom[30]; @@ -55,7 +67,7 @@ Filechx enfilechx ( Filechx f , File *fe){//fonction enfile un maillon choix en mch = (Maillonchx*) malloc ( sizeof (Maillonchx)); if ( mch == NULL ){ printf("Probleme malloc"); - return -1; + exit(-1); } fscanf ( fe , "%d %d %s %s %f %f %f %f %f %d", &nbcand, &numCand, nom, prenom, &nmat, &nfr, &nen, &nspe, &nDoss, &nbchoix ); for ( i = 0 ; i < nbchoix ; i++ ){ @@ -71,7 +83,75 @@ Filechx enfilechx ( Filechx f , File *fe){//fonction enfile un maillon choix en } return f; } +*/ + +//celle là c'est la bonne pour enfiler dans une file de choix +Filechx enf(Filechx fchx, Choix c) +{ + Maillonchx *m; + m = (Maillonchx*)malloc(sizeof(Maillonchx)); + if (m == NULL){printf("err pb malloc maillon choix\n");exit(-1);} + strcpy(m->chx.ville, c.ville); + strcpy(m->chx.dptmt, c.dptmt); + m->chx.dec = c.dec; + m->chx.valid = c.valid; + m->suivchx = NULL; + if (testVideChx (fchx)) + { + fchx.ttchx = m; + fchx.kechx = m; + } + else + { + fchx.kechx->suivchx = m; + fchx.kechx = m; + } + return fchx; +} + + + + + +Filecand enfC(Filecand fC, Candidat c) +{ + Mailloncand *m; + int cpt; + m = (Mailloncand *)malloc(sizeof(Mailloncand)); + if (m == NULL){printf("pb malloc\n"); exit(-1);} + m->cand.nEtu = c.nEtu; + strcpy(m->cand.nom , c.nom); + strcpy(m->cand.prenom, c.prenom); + m->cand.moymat = c.moymat; + m->cand.moyfr = c.moyfr; + m->cand.moyen = c.moyen; + m->cand.moyspe = c.moyspe; + m->cand.noteDoss = c.noteDoss; + m->cand.nbchx = c.nbchx; + m->cand.fchx = initchx(); + for (cpt = 0; cpt < c.nbchx; cpt++) + { + if (c.fchx.ttchx == NULL) break; + m->cand.fchx = enf(m->cand.fchx, c.fchx.ttchx->chx); + c.fchx.ttchx = c.fchx.ttchx->suivchx; + } + m->suivcand = NULL; + if (testVideCand(fC)) + { + fC.ttcand = m; + fC.kecand = m; + } + else + { + fC.kecand->suivcand = m; + fC.kecand = m; + } + return fC; + +} + +/* // FAIRE LECTURE CANDIDAT POUR METTRE EN PARALLELE Filecand enfilecand (Filecand f, FILE *fe){// fonction enfile un maillon cand en fin de file Candidat @@ -100,7 +180,7 @@ Filecand enfilecand (Filecand f, FILE *fe){// fonction enfile un maillon cand en int chargement (void){// chargement des files cand et chx } - +*/ @@ -115,64 +195,8 @@ Choix lireC(FILE *fe)//fonction extraite de la partie 2 } -Listechx InsertTC(Listechx list, Choix m)//Insert en tête de la liste -{ - Maillonchx *mchx; - mchx = (Maillonchx*)malloc(sizeof(Maillonchx)); - if (mchx == NULL){printf("pb malloc"); exit(-1);} - mchx->chx = m; - mchx->suivchx = list; - return mchx; -} - - -Listechx InsertC(Listechx list, Choix m)//insert globalement dans liste de choix -{ - if (list == NULL){return InsertTC(list, m);} - if (strcmp(list->chx.dptmt, m.dptmt)>0){return InsertTC(list, m);} - list->suivchx = InsertC(list->suivchx, m); - return list; -} - - -Listecand InsertT(Listecand list, Candidat c)//Insert en tête de la liste -{ - Mailloncand *c1; - - c1 = (Mailloncand*)malloc(sizeof(Mailloncand)); - if (c1 == NULL){printf("pb malloc"); exit;} - c1->cand.nEtu = c.nEtu; - strcpy(c1->cand.nom, c.nom); - strcpy(c1->cand.prenom, c.prenom); - c1->cand.moymat = c.moymat; - c1->cand.moyfr = c.moyfr; - c1->cand.moyen = c.moyen; - c1->cand.moyspe = c.moyspe; - c1->cand.noteDoss = c.noteDoss; - c1->cand.nbchx = c.nbchx; - c1->cand.lchx = c.lchx; - c1->suivcand = list; - return c1; -} - - -Listecand Insert(Listecand list, Candidat c)//insert globalement -{ - if (list == NULL){return InsertT(list, c);} - if (strcmp(list->cand.nom, c.nom)>0){return InsertT(list, c);} - list->suivcand = Insert(list->suivcand, c); - return list; -} - -Listecand InsertN(Listecand list, Candidat c)//insert globalement en fonction de la note -{ - if (list == NULL){return InsertT(list, c);} - if (list->cand.noteDoss <=+ c.noteDoss){return InsertT(list, c);} - list->suivcand = InsertN(list->suivcand, c); - return list; -} - +/*gardant ce modèle il nous faudra faire le chargement de files Listecand Chargementlistecandidat(FILE *fe, Listecand lC, int *nbC)// fonction de chargement de la liste des candidats { int cpt, j; @@ -196,17 +220,25 @@ Listecand Chargementlistecandidat(FILE *fe, Listecand lC, int *nbC)// fonction d } return lC; } - - - - - - - - - - - +*/ +Filecand ChargementfileC(Filecand fC, int *nbC)//chargement du fichier dans cette liste de candidats avec le nombre nbC de candidats à lire dans le fichier +{ + FILE *fe; + int cpt; + fe = fopen("part4.don", "r"); + if (fe == NULL){printf("pb ouv part4.don\n"); exit(-1);} + printf("ollow\n"); + fscanf(fe, "%d", nbC); + for (cpt = 0; cpt < *nbC; cpt ++) + { + puts("here"); + Candidat c; + c = lireCa(fe); + fC = enfC(fC, c); + } + fclose(fe); + return fC; +} @@ -216,9 +248,15 @@ void test (void){ fe = fopen( "part4.don", "r"); if ( fe == NULL ){ printf(" probleme d'ouverture de fichier"); - return -1; + return; } + Filecand fC; + int nbC; + printf("bon\n"); + fC = initcand(); + printf("jour\n"); + fC = ChargementfileC(fC, &nbC); -} \ No newline at end of file +} diff --git a/part4.h b/part4.h index 15972f4..00aa8bd 100644 --- a/part4.h +++ b/part4.h @@ -26,7 +26,7 @@ typedef struct { float moyspe;//moyenne en spécialité float noteDoss;//note après étude du dossier int nbchx;//nombre de choix - Listechx lchx; + Filechx fchx; }Candidat; @@ -45,9 +45,12 @@ Filechx initchx (void);// initialise une file choix a NULL Filecand initcand (void);// initialise une file candidat a NULL int testVideCand (Filecand f);// fonction test si la Filecand est vide return 1 sinon 0 Candidat lireCa(FILE *fe);//Lire une structure candidat a partir d'un fichier -Filechx enfilechx ( Filechx f , File *fe);//fonction enfile un maillon choix en fin de file Choix -Filecand enfilecand (Filecand f, FILE *fe);// fonction enfile un maillon cand en fin de file Candidat - +//Filechx enfilechx ( Filechx f , File *fe);//fonction enfile un maillon choix en fin de file Choix +//Filecand enfilecand (Filecand f, FILE *fe);// fonction enfile un maillon cand en fin de file Candidat +Choix lireC(FILE *fe);//fonction extraite de la partie 2 +Filecand enfC(Filecand fC, Candidat c); +Filechx enf(Filechx fchx, Choix c); +void test (void);