diff --git a/part2.c b/part2.c index a41b4fb..7f62f4e 100644 --- a/part2.c +++ b/part2.c @@ -24,6 +24,18 @@ Choix lirechx (void){//Fonction qui va lire les choix de la ville et du departem } +Choix lireC(FILE *fe) +{ + Choix c; + fscanf(fe, "%s%*c", c.ville); + fgets(c.dptmt, 26, fe); + c.dptmt[strlen(c.dptmt)-1]= '\0'; + fscanf(fe, "%d %d%*c", &c.dec, &c.valid); + printf("J'ai bien été scanné\n"); + return c; +} + + Candidat lireCandidat(void)//fonction qui lit un candidat sur le clavier { @@ -51,42 +63,58 @@ Candidat lireCandidat(void)//fonction qui lit un candidat sur le clavier } +Candidat lireCa(FILE *fe) +{ + 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 = NULL;//initialisation de la liste + + return c; +} -/* -Choix * chargeChoix(Choix *tchoix, TAILLE, nbchx){ +Listechx InsertTC(Listechx list, Maillonchx 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.chx; + mchx->suivchx = list; + return mchx; } -*/ +Listechx InsertC(Listechx list, Maillonchx m)//insert globalement dans liste de choix +{ + if (list == NULL){return InsertTC(list, m);} + if (strcmp(list->chx.dptmt, m.chx.dptmt)>0){return InsertTC(list, m);} + list->suivchx = InsertC(list->suivchx, m); + return list; +} void AffC(Candidat c) { - printf("%d", c.nEtu); - printf("%s \n %s\n", c.nom, c.prenom); + printf("%d\n", c.nEtu); + printf("%s\n%s\n", c.nom, c.prenom); printf("%.2f\t%.2f\t%.2f\t%.2f\n", c.moymat,c.moyfr, c.moyen, c.moyspe); printf("%d\n", c.nbchx); } - -Candidat lireFich1Cand (FILE * fe){ - Candidat cand; - - fgets(cand.nom, 20, fe); - cand.nom[strlen(cand.nom)-1]= '\0'; - - fgets(cand.prenom, 20, fe); - cand.prenom[strlen(cand.prenom)-1]= '\0'; - - fscanf(fe, "%f", &cand.moymat); - fscanf(fe, "%f", &cand.moyfr); - fscanf(fe, "%f", &cand.moyen); - fscanf(fe, "%f", &cand.moyspe); - fscanf(fe, "%d%*c", &cand.nbchx); - - return cand; +void AffCh(Choix c) +{ + printf("%s \n", c.ville); + printf("%s \n", c.dptmt); + printf("%d \n", c.dec); + printf("%d \n", c.valid); } //######################################### LISTES ########################################## @@ -95,11 +123,21 @@ Candidat lireFich1Cand (FILE * fe){ void AffListeCandidat (Listecand l){ - if ( l == NULL) return; + if (l == NULL) return; AffC(l->cand); + if (l->cand.lchx == NULL){printf("whybitch");} + AffListChoix(l->cand.lchx); AffListeCandidat(l->suivcand); } + +void AffListChoix(Listechx l) +{ + if (l == NULL) return; + AffCh(l->chx); + AffListChoix(l->suivchx); +} + Listecand recherchenom (Listecand l, char *nom ){ if ( l == NULL ){ return l;} if ( strcmp ( l->cand.nom, nom ) == 0) return l; @@ -118,6 +156,7 @@ Listecand InsertT(Listecand list, Candidat c)//Insert en tête de la liste 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; @@ -125,9 +164,9 @@ Listecand InsertT(Listecand list, Candidat c)//Insert en tête de la liste c1->cand.moyen = c.moyen; c1->cand.moyspe = c.moyspe; c1->cand.nbchx = c.nbchx; + c1->cand.lchx = c.lchx; c1->suivcand = list; return c1; - } @@ -139,41 +178,51 @@ Listecand Insert(Listecand list, Candidat c)//insert globalement return list; } -void Chargementlistecandidat( Mailloncand *cand, char *nameFile, int *n)// fonction de chargement de la liste des candidats -{ - FILE *f; - Maillon *tmp; - int n = 0, cpt, nbcand; - - f = fopen(nameFile, "r"); - if (f == NULL){printf("pb ouv file"); return -1;} - fscanf(f, "%d", n); - for ( int j = 0; j < = n; j++ ) +Listecand Chargementlistecandidat(FILE *fe, Listecand lC, int *nbC)// fonction de chargement de la liste des candidats +{ + int cpt, j; + fscanf(fe, "%d", nbC); + for (j = 1; j <= *nbC; j++) { - - cand = (Mailloncand *)malloc(sizeof(Mailloncand)); - if (cand == NULL){printf("pb malloc");exit();} - - fscanf(f, " %d %s %s %f %f %f %f %d ", &cand->cand.nEtu, cand->cand.nom, cand->cand.prenom, &cand->cand.moymat, &cand->cand.moyfr, &cand->cand.moyen, &cand->cand.moyspe, &cpt); - - for (cpt; cpt > 0; cpt--) + Candidat Ca; + fscanf(fe, "%d %s%*c", &Ca.nEtu, Ca.nom); + fgets(Ca.prenom, 31, fe); + Ca.prenom[strlen(Ca.prenom)-1]= '\0'; + fscanf(fe,"%f %f %f %f %d%*c", &Ca.moymat, &Ca.moyfr, &Ca.moyen, &Ca.moyspe, &Ca.nbchx); + Ca.lchx=NULL; + + for (cpt = Ca.nbchx; cpt >= 1; cpt--) { - Maillonchx *chx; - chx = (Maillonchx*)malloc(sizeof(Maillonchx));//création du maillon - if (chx == NULL){printf("pb malloc"); exit;} - lireM(f, chx);//lire le maillon avec la fonction plus haut - chx->ldept = Insert(tmp->lchx, chx);//insert le maillon à sa bonne place + printf("je passe et je marche\n"); + Maillonchx chx; + Choix c; + c = lireC(fe);//lire le maillon avec la fonction plus haut + chx.chx = c;//le choix du maillon est celui lu au dessus + Ca.lchx = InsertC(Ca.lchx, chx);//insert le maillon à sa bonne place } - i++; + lC = Insert(lC, Ca); } - return i; + return lC; +} + +void testchgt(void) +{ + int nbC = 0; + Listecand lC=NULL; + FILE *fe; + + fe=fopen("part2.don", "r"); + if (fe == NULL){printf("pb ouv file"); return;} + lC = Chargementlistecandidat(fe, lC, &nbC); + AffListeCandidat(lC); } + void test (void){ int menu1, menugest1, numet; diff --git a/part2.don b/part2.don index 4ef487b..18f67b5 100644 --- a/part2.don +++ b/part2.don @@ -1,14 +1,9 @@ 4 - 35 Durand - Jean Jacques - 15.75 12.25 9.5 17.00 - 3 - Clermont-Ferrand Informatique 0 @@ -24,13 +19,9 @@ Bio-Informatique 36 Dupont - Jeannine - 10.2 15.65 12.45 18.00 - 2 - Clermont-Ferrand Informatique 0 @@ -42,13 +33,9 @@ Informatique 37 Thérèse - Francoise - 10.5 12.65 14.45 16.00 - 1 - Clermont-Ferrand Bio-Informatique 0 @@ -56,13 +43,9 @@ Bio-Informatique 38 Henry - Bertrand - 5.2 14.65 11.23 14.00 - -3 - +2 Clermont-Ferrand Informatique 0 diff --git a/part2.h b/part2.h index dcaa594..d9b0c95 100644 --- a/part2.h +++ b/part2.h @@ -5,7 +5,7 @@ finalité : SAE 1.02 Algorithme */ /* - Brief : + Brief : */ #define TAILLE 100; @@ -17,15 +17,15 @@ typedef struct { int valid;//validation du candidat }Choix; -typedef struct Liste1{ + +typedef struct Listchx{ Choix chx; - struct List1 * suivchx; + struct Listchx * suivchx; }Maillonchx; typedef Maillonchx * Listechx; - typedef struct { int nEtu;//numéro d'étudiant char nom[20];//nom de l'étudiant @@ -35,52 +35,38 @@ typedef struct { float moyen;//moyenne en anglais float moyspe;//moyenne en spécialité int nbchx;//nombre de choix - Choix * lchx; -}Candidat; + Listechx lchx; +}Candidat; + + + -typedef struct Liste{ + +typedef struct Mailloncand{ Candidat cand; - struct Liste * suivcand; + struct Mailloncand * suivcand; }Mailloncand; typedef Mailloncand * Listecand; Choix lirechx (void); +Choix lireC(FILE *fe); Candidat lireCandidat(void); +Candidat lireCa(FILE *fe); +Listechx InsertTC(Listechx list, Maillonchx m); +Listechx InsertC(Listechx list, Maillonchx m); + void AffC(Candidat c); -Candidat lireFich1Cand (FILE * fe); +void AffCh(Choix c); void AffListeCandidat (Listecand l); +void AffListChoix(Listechx l); Listecand recherchenom (Listecand l, char *nom ); Listecand recherchenum (Listecand l, int num); +Listecand Chargementlistecandidat(FILE *fe, Listecand lC, int *nbC); +Listecand Insert(Listecand list, Candidat c); +Listecand InsertT(Listecand list, Candidat c); void test (void); - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void testchgt(void); +void affpartonsenpete(Listecand lC, int nbC); diff --git a/tpart2.c b/tpart2.c index b21cc82..23300b4 100644 --- a/tpart2.c +++ b/tpart2.c @@ -6,6 +6,6 @@ int main(void) { - test(); + testchgt(); return 0; -} \ No newline at end of file +}