diff --git a/src/I/un.c b/src/I/un.c index efd70c2..9bb273d 100644 --- a/src/I/un.c +++ b/src/I/un.c @@ -17,6 +17,7 @@ #include "../II/deux.c" void identificationCandidat(int* id, ListeCandidats* listePointer, int* nbCandidats) { + Candidat* candidat; char connexion, poubelle; int verif; @@ -56,7 +57,7 @@ void identificationCandidat(int* id, ListeCandidats* listePointer, int* nbCandid if(connexion == 'n' || connexion == 'N') { printf("\nTrès bien, nous allons donc précéder à votre enregistrement.\n\n"); - Candidat* candidat = creerCandidat(); // malloc + candidat = creerCandidat(); // malloc printf("Nom de famille : "); scanf("%*c%[^\n]", candidat->nom); @@ -116,8 +117,10 @@ void titreMenuPrincipal(void) { } void menuCandidat(VilleIUT** tiut, ListeCandidats* listePointer, int nbVilles, int* nbCandidats) { - char poubelle; // Permet de stocker les caractères aspirés en trop sur stdin lors du choix dans le menu + // poubelle: Permet de stocker les caractères aspirés en trop sur stdin lors du choix dans le menu + char poubelle, searchIUT[LEN_MAX], searchDept[LEN_MAX]; Candidat* candidat; + // choix: Contient le choix de l'utilisateur dans le menu / id: contient id user si login / status: candidatures ouvertes ou fermées int choix, id = 0, status = readStatus(); char connexion; @@ -167,7 +170,6 @@ void menuCandidat(VilleIUT** tiut, ListeCandidats* listePointer, int nbVilles, i printf("Voir les disponibilités des départements dans un IUT...\n\n"); printf("Saisissez le nom de la ville recherchée (tapez q pour annuler) : "); - char searchIUT[LEN_MAX]; scanf("\n%[^\n]", searchIUT); if(strcasecmp(searchIUT, "q") == 0) @@ -179,7 +181,6 @@ void menuCandidat(VilleIUT** tiut, ListeCandidats* listePointer, int nbVilles, i printf("Rechercher un département...\n\n"); printf("Saisissez le nom du département recherché (tapez q pour annuler) : "); - char searchDept[LEN_MAX]; scanf("\n%[^\n]", searchDept); if(strcasecmp(searchDept, "q") == 0) @@ -547,7 +548,7 @@ void menuPrincipal(/* TODO: prise en compte des status actuels du recrutement */ // FONCTIONS MENU ADMIN void menuAdmin_modifierPlaces(VilleIUT** tiut, int nbVilles) { - int nbPlaces; + int nbPlaces, code; char searchIUT[LEN_MAX], searchDept[LEN_MAX]; printf("Entrez une ville (tapez q pour annuler) : "); scanf("\n%[^\n]", searchIUT); @@ -555,7 +556,7 @@ void menuAdmin_modifierPlaces(VilleIUT** tiut, int nbVilles) { if(strcasecmp(searchIUT, "q") == 0) return; - int code = afficherListeDepartement(tiut, nbVilles, searchIUT); + code = afficherListeDepartement(tiut, nbVilles, searchIUT); if(code != -1) { printf("Quel département souhaitez-vous modifier ? : "); @@ -568,6 +569,7 @@ void menuAdmin_modifierPlaces(VilleIUT** tiut, int nbVilles) { } void menuAdmin_creerIUT(VilleIUT*** tiutPointer, int* nbVilles) { + VilleIUT* ville; char nameIUT[LEN_MAX]; printf("Entrez le nom de la ville (tapez q pour annuler) : "); scanf("\n%[^\n]", nameIUT); @@ -575,7 +577,7 @@ void menuAdmin_creerIUT(VilleIUT*** tiutPointer, int* nbVilles) { if(strcasecmp(nameIUT, "q") == 0) return; - VilleIUT* ville = creerVille(); + ville = creerVille(); strcpy(ville->ville, nameIUT); ajouterVille(tiutPointer, ville, nbVilles); @@ -641,6 +643,7 @@ void menuAdmin_creerDepartement(VilleIUT** tiut, int nbVilles) { void menuAdmin_supprimerDepartement(VilleIUT** tiut, int nbVilles) { if(readStatus() == 0) { + int i; char searchIUT[LEN_MAX], searchDept[LEN_MAX]; VilleIUT* ville; @@ -651,7 +654,7 @@ void menuAdmin_supprimerDepartement(VilleIUT** tiut, int nbVilles) { if(strcasecmp(searchIUT, "q") == 0) return; - int i = rechercherVille(tiut, nbVilles, searchIUT); + 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); @@ -744,6 +747,7 @@ ListeDept creerListeDepartement(void) { } int afficherListeDepartement(VilleIUT** tiut, int nbVilles, char* searchIUT) { + ListeDept ldept; int i = rechercherVille(tiut, nbVilles, searchIUT); if(i == -1) { @@ -751,7 +755,7 @@ int afficherListeDepartement(VilleIUT** tiut, int nbVilles, char* searchIUT) { return -1; } - ListeDept ldept = tiut[i]->ldept; + ldept = tiut[i]->ldept; if(ldept == NULL) fprintf(stderr, "\n\e[1;91mErreur: la ville '%s' ne contient aucun département\e[0m\n\n", tiut[i]->ville); @@ -770,18 +774,20 @@ int afficherListeDepartement(VilleIUT** tiut, int nbVilles, char* searchIUT) { } void afficherDepartement(VilleIUT** tiut, int nbVilles, char* searchDept) { + int i, nb=0; + ListeDept ldept, search; + printf("\n\e[4;37mListe des IUT contenant le département '%s':\e[0m\n\n", searchDept); - int i, nb=0; for(i=0; ildept; + ldept = tiut[i]->ldept; if(ldept != NULL) { if(strcasecmp(ldept->departement, searchDept) == 0) { printf(" - %s\n", tiut[i]->ville); nb++; } else { - ListeDept search = ldept; + search = ldept; while(search->suiv != NULL) { search = search->suiv; @@ -833,12 +839,13 @@ ListeDept ajouterDepartement(ListeDept ldept, MaillonDept* dept) { ListeDept supprimerDepartement(ListeDept ldept, char* searchDept) { int foundDept=0; + ListeDept search, tmp; if(strcasecmp(ldept->departement, searchDept) == 0) { ldept = ldept->suiv; foundDept = 1; } else { - ListeDept search = ldept, tmp; + search = ldept; while(search->suiv != NULL && strcasecmp(search->departement, searchDept) != 0) { tmp = search; @@ -861,13 +868,14 @@ ListeDept supprimerDepartement(ListeDept ldept, char* searchDept) { void modifierNbPlaces(VilleIUT** tiut, int nbVilles, char* searchIUT, char* searchDept, int nb) { int foundDept=0, i = rechercherVille(tiut, nbVilles, searchIUT); + ListeDept ldept, search; if(i == -1) { fprintf(stderr, "\n\e[1;91mErreur: la ville '%s' n'est pas dans la liste des IUT.\e[0m\n\n", searchIUT); return; } - ListeDept ldept = tiut[i]->ldept; + ldept = tiut[i]->ldept; if(ldept != NULL) { if(strcasecmp(ldept->departement, searchDept) == 0) { @@ -875,7 +883,7 @@ void modifierNbPlaces(VilleIUT** tiut, int nbVilles, char* searchIUT, char* sear ldept->nbP = nb; foundDept = 1; } else { - ListeDept search = ldept; + search = ldept; while(search->suiv != NULL) { search = search->suiv; @@ -893,6 +901,7 @@ void modifierNbPlaces(VilleIUT** tiut, int nbVilles, char* searchIUT, char* sear } void modifierNomResponsable(VilleIUT** tiut, int nbVilles, char* searchIUT, char* searchDept, char* nom) { + ListeDept ldept, search; int foundDept=0, i = rechercherVille(tiut, nbVilles, searchIUT); if(i == -1) { @@ -900,7 +909,7 @@ void modifierNomResponsable(VilleIUT** tiut, int nbVilles, char* searchIUT, char return; } - ListeDept ldept = tiut[i]->ldept; + ldept = tiut[i]->ldept; if(ldept != NULL) { if(strcasecmp(ldept->departement, searchDept) == 0) { @@ -908,7 +917,7 @@ void modifierNomResponsable(VilleIUT** tiut, int nbVilles, char* searchIUT, char printf("\n\e[1;32mLe responsable de la formation '%s' à l'IUT '%s' est désormais '%s'.\e[0m\n\n", searchDept, searchIUT, ldept->responsable); foundDept = 1; } else { - ListeDept search = ldept; + search = ldept; while(search->suiv != NULL) { search = search->suiv; @@ -926,6 +935,10 @@ void modifierNomResponsable(VilleIUT** tiut, int nbVilles, char* searchIUT, char } void saveVilles(VilleIUT* tiut[], int nbVilles) { + int i, longueurNomVille, nbDepartements, lenDepartement, lenNomResponsable; + VilleIUT ville; + MaillonDept* maillon; + FILE *fe = fopen("donnees/villes.bin", "wb"); if(fe == NULL) { @@ -935,15 +948,15 @@ void saveVilles(VilleIUT* tiut[], int nbVilles) { fwrite(&nbVilles, sizeof(int), 1, fe); - for (int i = 0; i < nbVilles; i++) { - VilleIUT ville = *tiut[i]; + for (i=0; isuiv; @@ -952,13 +965,13 @@ void saveVilles(VilleIUT* tiut[], int nbVilles) { maillon = ville.ldept; while (maillon != NULL) { - int lenDepartement = strlen(maillon->departement)+1; + lenDepartement = strlen(maillon->departement)+1; fwrite(&lenDepartement, sizeof(int), 1, fe); fwrite(maillon->departement, sizeof(char), lenDepartement, fe); fwrite(&maillon->nbP, sizeof(int), 1, fe); - int lenNomResponsable = strlen(maillon->responsable)+1; + lenNomResponsable = strlen(maillon->responsable)+1; fwrite(&lenNomResponsable, sizeof(int), 1, fe); fwrite(maillon->responsable, sizeof(char), lenNomResponsable, fe); @@ -972,6 +985,11 @@ void saveVilles(VilleIUT* tiut[], int nbVilles) { } VilleIUT** readVilles(int* nbVilles) { + VilleIUT** tiut; + VilleIUT* ville; + MaillonDept* maillon, *maillonPrecedent; + int i, lenNomVille, nbDepartements, lenDepartement, lenNomResponsable; + FILE *fe = fopen("donnees/villes.bin", "rb"); if(fe == NULL) { @@ -981,34 +999,32 @@ VilleIUT** readVilles(int* nbVilles) { fread(nbVilles, sizeof(int), 1, fe); - VilleIUT** tiut = (VilleIUT**) malloc(*nbVilles*sizeof(VilleIUT*)); + tiut = (VilleIUT**) malloc(*nbVilles*sizeof(VilleIUT*)); if(tiut == NULL) { perror("malloc"); exit(errno); } - for (int i = 0; i < *nbVilles; i++) { - VilleIUT* ville = (VilleIUT*) malloc(sizeof(VilleIUT)); + for (i=0; i<*nbVilles; i++) { + ville = (VilleIUT*) malloc(sizeof(VilleIUT)); if(ville == NULL) { perror("malloc"); exit(errno); } - int lenNomVille; fread(&lenNomVille, sizeof(int), 1, fe); fread(ville->ville, sizeof(char), lenNomVille, fe); - int nbDepartements; fread(&nbDepartements, sizeof(int), 1, fe); ville->ldept = creerListeDepartement(); - MaillonDept* maillonPrecedent = NULL; + maillonPrecedent = NULL; int j; for (j=0; jsuiv = maillon; - int lenDepartement; fread(&lenDepartement, sizeof(int), 1, fe); fread(maillon->departement, sizeof(char), lenDepartement, fe); fread(&maillon->nbP, sizeof(int), 1, fe); - int lenNomResponsable; fread(&lenNomResponsable, sizeof(int), 1, fe); fread(maillon->responsable, sizeof(char), lenNomResponsable, fe);