diff --git a/part2.c b/part2.c index 5e3432e..d512b2b 100644 --- a/part2.c +++ b/part2.c @@ -11,12 +11,10 @@ Choix lirechx (void){//Fonction qui va lire les choix de la ville et du departem Choix chx; printf("Saisir le choix de la ville \n"); - fgets(chx.ville, 20, stdin); - chx.ville[strlen(chx.ville)-1]= '\0'; + scanf( "%s", chx.ville); printf("Saisir le choix du departement d'étude\n"); - fgets(chx.dptmt, 20, stdin); - chx.dptmt[strlen(chx.dptmt)-1]= '\0'; + scanf("%s" , chx.dptmt); chx.dec = 0; chx.valid = 0; @@ -91,6 +89,7 @@ Listechx InsertTC(Listechx list, Choix m)//Insert en tête de la liste } + Listechx InsertC(Listechx list, Choix m)//insert globalement dans liste de choix { if (list == NULL){return InsertTC(list, m);} @@ -149,6 +148,23 @@ Listecand recherchenum (Listecand l, int num){ return recherchenum (l->suivcand, num ); } +Listechx recherchechx (Listechx l, char *nom )//recherche du nom de département dans la liste +{ + if ( l == NULL ){ return l;} + if ( strcmp ( l->chx.dptmt, nom ) == 0) return l; + return recherchechx (l->suivchx, nom ); +} + +Listechx majchoix (Listechx chx, Choix c){//Mise à jour du de la liste choix en modifiant un maillon + + strcpy(chx->chx.ville, c.ville); + strcpy (chx->chx.dptmt, c.dptmt); + chx->chx.dec = c.dec; + chx->chx.valid = c.valid; + + return chx; +} + Listecand InsertT(Listecand list, Candidat c)//Insert en tête de la liste { Mailloncand *c1; @@ -206,25 +222,19 @@ Listecand Chargementlistecandidat(FILE *fe, Listecand lC, int *nbC)// fonction d return lC; } +Listechx suppressionchxT (Listechx l){//Fonction suppression d'un maillon + Listechx tmp; + tmp = l->suivchx; + free(l); + return tmp; +} - -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); +Listechx suppressionchx(Listechx l , char *depart){//suppression d'un maillon viale nom de son departement + if ( l == NULL) return l; + if ( strcmp ( depart, l->chx.dptmt ) == 0 ) + return suppressionchxT(l); + l->suivchx = suppressionchx( l->suivchx , depart); + return l; } @@ -268,21 +278,26 @@ void saveChx(Listechx lCh, FILE *fs) void test (void){ - int menu1, menugest1, numet,modifcand; - char nomet[20]; + int menu1, menugest1, numet,modifcand, cont = 0, nbC; + char nomet[20], nomdpt[20], nomville[20]; Candidat cand1; Choix choix1; Listecand lcand, l2cand; + Listechx chx; + FILE *fe; + fe = fopen ("part2.don", "r"); + if ( fe == NULL ){printf("prob ouverture fichier\n"); return;} + lcand = Chargementlistecandidat(fe, lcand, &nbC); 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); printf("%d", menu1); - while (menu1 != 1 && menu1 !=2){// Traitement des erreurs + while (menu1 != 1 && menu1 !=2 ){// Traitement des erreurs printf("Erreur de saisie veuillez refaire votre choix ! \n"); printf("(1) Gestion Candidature\n"); printf("(2) Affichage Candidature\n"); @@ -307,19 +322,51 @@ void test (void){ else if (menugest1 == 2){// - printf("Entrer le numéro de candidat\n"); - scanf("%d",&modifcand ); + printf("Veuillez renseigner votre nom d'étudiant\n"); + scanf("%s", nomet); + l2cand = recherchenom ( lcand, nomet ); + printf("Entrer le nom du departement de l candidature concernée\n"); + scanf("%s", nomdpt); + //PROBLEME SUR L'ASSIGNATION DU RESULTAT DE RECHERCHE... J'ARRIVE PAS + l2cand->cand.lchx = recherchechx(l2cand->cand.lchx, nomdpt); + while ( l2cand->cand.lchx->chx.dptmt == NULL){ + printf("departement inconnu veuillez saisir à nouveau\n"); + scanf("%s", nomdpt); + l2cand->cand.lchx = recherchechx(l2cand->cand.lchx , nomdpt); + } + choix1 = lirechx(); - //FONCTION MISE A JOUR LISTE AVEC AFFICHAGE NOUVELLE LISTE + l2cand->cand.lchx = majchoix(l2cand->cand.lchx, choix1); + AffListeCandidat(l2cand); } - //else if (menugest1 == 3) - //FONCTION SUPPRESSION LISTE AVEC AFFICHAGE NOUVELLE LISTE - //} - //else if (menu1 == 2){ - printf(""); + else if (menugest1 == 3){ + printf("Veuillez renseigner votre nom d'étudiant\n"); + scanf("%s", nomet); + l2cand = recherchenom ( lcand, nomet ); + + printf("Entrer le nom du departement que vous souhaitez supprimer\n"); + scanf ("%s", nomdpt); + l2cand->cand.lchx = suppressionchx(l2cand->cand.lchx , nomdpt ); + printf("Voici votre nouvelle liste de candidature\n"); + AffListeCandidat(l2cand); + } + + } + else if (menu1 == 2){ + printf("Entrer le nom du departement dont vous souhaitez afficher les candidats"); + scanf("%s", nomdpt); + + printf("Entrer le nom de la ville dans laquelle se trouve le departement en question\n"); + scanf("%s", nomville); + + //FAIRE UNE FONCTION DE RECHERCHE RECURSIVE + /*FONCTION AFFICHE (CANDIDATS , VILLE, DEPARTEMENT) + EX : SI L->CHX.VILLE == VILLE && L->CHX.DEPARTEMENT == DEPARTEMENT + ALORS AFFICHE MAILLON CANDIDAT + RETURN AFFICHE CANDIDAT->SUIVANT, VILLE, DEPARTEMENT) } } diff --git a/part2.h b/part2.h index 81020e8..9103b8a 100644 --- a/part2.h +++ b/part2.h @@ -60,7 +60,11 @@ void AffListeCandidat (Listecand l);//affiche complet de la liste de candidats void AffListChoix(Listechx l);//affichage complet de la liste de choix Listecand recherchenom (Listecand l, char *nom );//recherche par un nom dans une liste de candidats Listecand recherchenum (Listecand l, int num);//recherche par le numéro dans une liste de candidats +Listechx recherchechx (Listechx l, char *nom );// recherche par le nom d'un depratement dans une listedederpartement +Listechx majchoix (Listechx chx, Choix c);// mise jour d'un choix Listecand Chargementlistecandidat(FILE *fe, Listecand lC, int *nbC);//chargement du fichier dans une liste de candidats +Listechx suppressionchxT (Listechx l);//Fonction suppression d'un maillon +Listechx suppressionchx(Listechx l , char *depart);//suppression d'un maillon viale nom de son departement Listecand Insert(Listecand list, Candidat c);//insertion en tête d'un maillon de type Candidat Listecand InsertT(Listecand list, Candidat c);//insertion globale d'un maillon de type Candidat void test (void);//fonction globale diff --git a/test b/test index 689c844..268402d 100644 Binary files a/test and b/test differ diff --git a/tpart2.c b/tpart2.c index 23300b4..e0b9cb4 100644 --- a/tpart2.c +++ b/tpart2.c @@ -6,6 +6,6 @@ int main(void) { - testchgt(); + test(); return 0; }