From 71a994ef5a90013fdaa14bd282a34cb6c5c6a434 Mon Sep 17 00:00:00 2001 From: Lucie GOIGOUX Date: Thu, 5 Jan 2023 10:18:13 +0100 Subject: [PATCH] Ajout de fonction --- src/II/deux.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/II/deux.c b/src/II/deux.c index 8163a7c..530cec5 100644 --- a/src/II/deux.c +++ b/src/II/deux.c @@ -61,6 +61,56 @@ void ajouterCandidature(Candidat* candidat, Candidature* candidature) { candidat->nbCandidatures+=1; } +void menuCandidat_candidater(VilleIUT** tiut, int nbVilles, Candidat* candidat) { + Candidature* candid = creerCandidature(); + + char searchIUT[LEN_MAX], searchDept[LEN_MAX]; + printf("Entrez la ville dans laquelle vous souhaitez candidater : "); + scanf("%s", searchIUT); + + if(strcasecmp(searchIUT, "q") == 0) + return; + + int i = rechercherVille(tiut, nbVilles, searchIUT); + + if(i == -1) { + fprintf(stderr, "\e[1;91mErreur: la ville '%s' n'est pas dans la liste des IUT.\e[0m\n\n", searchIUT); + return; + } + + printf("Entrez le département dans lequel vous souhaitez candidater : "); + scanf("%*c%[^\n]", searchDept); + + int found = 0; + ListeDept liste = tiut[i]->ldept; + + if(strcmp(liste->departement, searchDept) == 0) + found=1; + + while(liste->suiv != NULL) { + liste = liste->suiv; + if(strcmp(liste->departement, searchDept) == 0) + found=1; + } + + if(found == 0) { + fprintf(stderr, "\e[1;91mErreur: le département '%s' n'existe pas dans l'IUT '%s'.\e[0m\n\n", searchDept, searchIUT); + return; + } + + strcpy(candid->ville, searchIUT); + strcpy(candid->departement, searchDept); + + if(checkCandidature(candidat, *candid) == -1) { + fprintf(stderr, "\n\e[1;91mErreur: vous avez déjà candidaté pour le département '%s' dans l'IUT '%s'.\e[0m\n\n", searchDept, searchIUT); + return; + } + + ajouterCandidature(candidat, candid); + + printf("\n\e[1;32mVotre candidature au département '%s' à l'IUT '%s' a bien été prise en compte !\e[0m\n\n", searchDept, searchIUT); +} + int checkCandidature(Candidat* candidat, Candidature candid) { int nbCandidatures = candidat->nbCandidatures; @@ -83,6 +133,7 @@ void afficherListeCandidats(ListeCandidats liste, int nbCandidats) { for (int i=0; i