diff --git a/part2.c b/part2.c index b992afd..5e3432e 100644 --- a/part2.c +++ b/part2.c @@ -80,21 +80,21 @@ Candidat lireCa(FILE *fe) -Listechx InsertTC(Listechx list, Maillonchx m)//Insert en tête de la liste +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.chx; + mchx->chx = m; mchx->suivchx = list; return mchx; } -Listechx InsertC(Listechx list, Maillonchx m)//insert globalement dans liste de choix +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.chx.dptmt)>0){return InsertTC(list, m);} + if (strcmp(list->chx.dptmt, m.dptmt)>0){return InsertTC(list, m);} list->suivchx = InsertC(list->suivchx, m); return list; } @@ -198,10 +198,11 @@ Listecand Chargementlistecandidat(FILE *fe, Listecand lC, int *nbC)// fonction d 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 + Ca.lchx = InsertC(Ca.lchx, c);//insert le maillon à sa bonne place } lC = Insert(lC, Ca); } + fclose(fe); return lC; } @@ -212,24 +213,70 @@ void testchgt(void) int nbC = 0; Listecand lC=NULL; FILE *fe; - + printf("avantouverture\n"); fe=fopen("part2.don", "r"); if (fe == NULL){printf("pb ouv file"); return;} + printf("apres ouverture\n"); + lC = Chargementlistecandidat(fe, lC, &nbC); + printf("apres chargement\n"); + AffListeCandidat(lC); + printf("apres affichage\n"); + Save(lC, nbC); } +void Save(Listecand lC, int nbC) +{ + FILE *fs; + fs=fopen("part2.don", "w"); + if (fs == NULL){printf("pb ouv fichier part2.don\n");exit(-1);} + int cpt; + fprintf(fs, "%d\n", nbC); + + saveC(lC, fs); +} + +void saveC(Listecand lC, FILE *fs) +{ + if (lC == NULL)return; + fprintf(fs, "%d\n", lC->cand.nEtu); + fprintf(fs, "%s\n", lC->cand.nom); + fprintf(fs, "%s\n", lC->cand.prenom); + fprintf(fs, "%.2f\t %.2f\t %.2f\t %.2f\n", lC->cand.moymat, lC->cand.moyfr, lC->cand.moyen, lC->cand.moyspe); + fprintf(fs, "%d\n", lC->cand.nbchx); + saveChx(lC->cand.lchx, fs); + saveC(lC->suivcand, fs); +} + + + +void saveChx(Listechx lCh, FILE *fs) +{ + if (lCh == NULL)return; + fprintf(fs, "%s\n", lCh->chx.ville); + fprintf(fs, "%s\n", lCh->chx.dptmt); + fprintf(fs, "%d\n", lCh->chx.dec); + fprintf(fs, "%d\n", lCh->chx.valid); + saveChx(lCh->suivchx, fs); +} + + + void test (void){ - int menu1, menugest1, numet; + int menu1, menugest1, numet,modifcand; + char nomet[20]; Candidat cand1; + Choix choix1; Listecand lcand, l2cand; + printf("Menu :\n");//Premier affichage menu pour choisir si on veut afficher le menu d'un candidat ou toutes les candidatures printf("(1) Gestion Candidature\n(2) Affichage Candidature\n"); scanf("%d", &menu1); @@ -248,21 +295,24 @@ void test (void){ printf("(1) Ajouter une Candidature\n (2) Modifier une Candidature\n (3) Supprimer une Candidature"); scanf("%d", &menugest1); - if (menugest1 == 1){ - printf("Veuillez renseigner votre numéro d'étudiant\n"); - scanf("%d", &numet); - l2cand = recherchenum( lcand, numet); - AffListeCandidat(l2cand); - + if (menugest1 == 1){// Ajout d'une candidature (choix) a un candidat deja existant + printf("Veuillez renseigner votre nom d'étudiant\n"); + scanf("%s", nomet); + l2cand = recherchenom ( lcand, nomet ); - cand1 = lireCandidat(); - lcand = Insert(lcand , cand1); + choix1 = lirechx(); + lcand->cand.lchx = InsertTC (l2cand->cand.lchx,choix1); AffListeCandidat(lcand); } - //else if (menugest1 == 2) + else if (menugest1 == 2){// + printf("Entrer le numéro de candidat\n"); + scanf("%d",&modifcand ); + + //FONCTION MISE A JOUR LISTE AVEC AFFICHAGE NOUVELLE LISTE + } //else if (menugest1 == 3) //FONCTION SUPPRESSION LISTE AVEC AFFICHAGE NOUVELLE LISTE @@ -275,40 +325,6 @@ void test (void){ } -void Save(Listecand lC, int nbC) -{ - FILE *fs; - fs=fopen("part2.don", "w"); - if (fs == NULL){printf("pb ouv fichier part2.don\n");exit(-1);} - int cpt; - fprintf(fs, "%nbC\n", nbC); - - saveC(lC, fs); -} - -void saveC(Listecand lC, FILE *fs) -{ - if (lC == NULL)return; - fprintf(fs, "%d\n", lC->cand.nEtu); - fprintf(fs, "%s\n", lC->cand.nom); - fprintf(fs, "%s\n", lC->cand.prenom); - fprintf(fs, "%.2f\t %.2f\t %.2f\t %.2f\n", lC->cand.moymat, lC->cand.moyfr, lC->cand.moyen, lC->cand.moyspe); - fprintf(fs, "%d\n", lC->cand.nbchx); - saveChx(lC->cand.lchx, fs); - saveC(lC->suivcand, fs); -} - - - -void saveChx(Listechx lCh, FILE *fs) -{ - if (lCh == NULL)return; - fprintf(fs, "%s\n", lCh->chx.ville); - fprintf(fs, "%s\n", lCh->chx.dptmt); - fprintf(fs, "%d\n", lCh->chx.dec); - fprintf(fs, "%d\n", lCh->chx.valid); - saveChx(lCh->suivchx, fs); -} //####################################### FILES ################################################# diff --git a/part2.don b/part2.don index 18f67b5..f3228e8 100644 --- a/part2.don +++ b/part2.don @@ -1,50 +1,38 @@ 4 -35 -Durand -Jean Jacques -15.75 12.25 9.5 17.00 -3 +36 +Dupont +Jeannine +10.20 15.65 12.45 18.00 +2 Clermont-Ferrand Informatique 0 0 -Grenoble +Aurillac Informatique 0 0 +35 +Durand +Jean Jacques +15.75 12.25 9.50 17.00 +3 Aurillac Bio-Informatique 0 0 - -36 -Dupont -Jeannine -10.2 15.65 12.45 18.00 -2 Clermont-Ferrand Informatique 0 0 -Aurillac +Grenoble Informatique 0 0 - -37 -Thérèse -Francoise -10.5 12.65 14.45 16.00 -1 -Clermont-Ferrand -Bio-Informatique -0 -0 - 38 Henry Bertrand -5.2 14.65 11.23 14.00 +5.20 14.65 11.23 14.00 2 Clermont-Ferrand Informatique @@ -54,3 +42,12 @@ Aurillac Informatique 0 0 +37 +Thérèse +Francoise +10.50 12.65 14.45 16.00 +1 +Clermont-Ferrand +Bio-Informatique +0 +0 diff --git a/part2.h b/part2.h index 360a926..81020e8 100644 --- a/part2.h +++ b/part2.h @@ -50,8 +50,8 @@ Choix lirechx (void);//permet de lire un choix selon une entrée stdin Choix lireC(FILE *fe);//ermet de lire un choix avec un FILe de type fichier.don Candidat lireCandidat(void);//permet de lire un candidat avec le clavier Candidat lireCa(FILE *fe);//permet de lire un candidat selon le fichier.don -Listechx InsertTC(Listechx list, Maillonchx m);//insertion en tête d'un maillon de type choix -Listechx InsertC(Listechx list, Maillonchx m);//insertion globale d'un maillon de type choix +Listechx InsertTC(Listechx list, Choix m);//insertion en tête d'un maillon de type choix +Listechx InsertC(Listechx list, Choix m);//insertion globale d'un maillon de type choix void AffC(Candidat c);//affichage simple d'un candidat diff --git a/test b/test new file mode 100644 index 0000000..689c844 Binary files /dev/null and b/test differ