diff --git a/SAE.c b/SAE.c index 6dc92d1..ab4b6df 100644 --- a/SAE.c +++ b/SAE.c @@ -919,6 +919,13 @@ ListeCandid rechCandidIUT(ListeCandid l, char *code) return rechCandidIUT(l->suiv, code); } +void decalageGauche(Candidat **tab,int pos, int nbEle) +{ + int i; + for(i = pos; i < nbEle - 1; i++) + tab[i] = tab[i + 1]; +} + void supprimerCandid(Candidat **tab, int *nbEle) { int idSup, pos, trouve; @@ -940,9 +947,9 @@ void supprimerCandid(Candidat **tab, int *nbEle) suppressionCandid(tab[pos]->idCandIUT, tab[pos]->idCandIUT->iutCandid, tab[pos]->idCandIUT->tabDept, tab[pos]->idCandIUT->nbChoix); tab[pos]->idCandIUT = tab[pos]->idCandIUT->suiv; } - *nbEle = *nbEle - 1; free(tab[pos]); - triEchangecandid(tab, *nbEle + 1); + decalageGauche(tab, pos, *nbEle); + *nbEle = *nbEle - 1; return; if(!verifSelection()) @@ -1007,7 +1014,7 @@ void creationCandid(VilleIUT **tiut, int nbIUT, Candidat **tcandid, int *nbCandi printf("voulez vous faire votre choix maintenant (oui|non) : "); scanf("%s", choix); if (strcmp(choix, "oui")==0) - modifCandid(tcandid, *nbCandid, tiut, 0, c.id); + modifCandid(tcandid, *nbCandid, tiut, 0, *nbCandid - 1); if (strcmp(choix, "non")==0) break; return; @@ -1076,7 +1083,7 @@ void gestionCandid(VilleIUT **tiut, int nbIUT, Candidat **tcandid, int *nbCandid if (trouve == 0) printf("identifiant pas présent dans la base de donnée !\n"); else - modifCandid(tcandid, *nbCandid, tiut, nbIUT, id); + modifCandid(tcandid, *nbCandid, tiut, nbIUT, pos); system("clear"); break; case 4: @@ -1139,6 +1146,7 @@ int recherchecandidDept(ChoixDept **tab,int nbEle, char code[],int *trouve) *trouve = 1; return i; } + i = i + 1; } *trouve = 0; return -1; @@ -1159,6 +1167,7 @@ void ajouterDept(Candidat **tcandid, int nbCandid, VilleIUT **tiut, int nbIUT, i { char ville[30], departement[30]; int pos,irech, trouve; + MaillonDept *auxD; MaillonCandid *aux; aux = (MaillonCandid *)malloc(sizeof(MaillonCandid)); if (aux == NULL) @@ -1180,30 +1189,55 @@ void ajouterDept(Candidat **tcandid, int nbCandid, VilleIUT **tiut, int nbIUT, i { printf("Dans quel Département voulez-vous candidater : "); scanf("%s%*c", departement); - if (rechercheDept(tiut[pos]->idDept, departement) == NULL) + auxD = rechercheDept(tiut[pos]->idDept, departement); + if (auxD == NULL) printf("Erreur ! Département non référencé\n"); - if (rechercheDept(tiut[pos]->idDept, departement) != NULL) + if (auxD != NULL) { + printf("1\n"); aux = recherchecandidIUT(tcandid[iCandid]->idCandIUT, ville); + printf("2\n"); if (aux == NULL) { - tDept = (ChoixDept **)malloc(sizeof(ChoixDept *)*10); + printf("3\n"); + tDept = (ChoixDept **)malloc(10 * sizeof(ChoixDept *)); + printf("4\n"); if(tDept == NULL) { printf("Pb malloc candidIUt\n"); exit(1); } + printf("5\n"); + tDept[0] = (ChoixDept *)malloc(sizeof(ChoixDept)); + if (tDept[0] == NULL) + { + printf("pb malloc\n"); + exit(1); + } *(tDept[0]) = RempTabCandid(departement, 0, 0); + printf("%s %d %d\n",tDept[0]->departement, tDept[0]->decisionDept, tDept[0]->decisionCandid); + printf("6\n"); tcandid[iCandid]->idCandIUT = insererCandid(tcandid[iCandid]->idCandIUT, ville, tDept, 1); printf("Candidature Validée \n"); } - else + if (aux != NULL) { + printf("3\n"); irech = recherchecandidDept(aux->tabDept, aux->nbChoix, departement, &trouve); + printf("4\n"); if (irech == -1) { + printf("5\n"); + aux->tabDept[aux->nbChoix] = (ChoixDept *)malloc(sizeof(ChoixDept)); + if (aux->tabDept[aux->nbChoix] == NULL) + { + printf("Erreur Malloc \n"); + exit(1); + } *(aux->tabDept[aux->nbChoix]) = RempTabCandid(departement, 0, 0); + printf("6\n"); aux->nbChoix = aux->nbChoix + 1; + strcpy(aux->iutCandid, ville); printf("Candidature validée !\n"); } else @@ -1219,7 +1253,14 @@ void ajouterDept(Candidat **tcandid, int nbCandid, VilleIUT **tiut, int nbIUT, i if(!verifSelection()) break; } - free(aux); + return; +} + +void decalageGaucheDept(ChoixDept **tab, int pos, int nbEle) +{ + int i; + for(i = pos; i < nbEle - 1; i++) + tab[i] = tab[i + 1]; } void supprimerCandidDept(Candidat **tcandid, int nbCandid, VilleIUT **tiut, int nbIUT, int iCandid) @@ -1247,6 +1288,7 @@ void supprimerCandidDept(Candidat **tcandid, int nbCandid, VilleIUT **tiut, int printf("Annulation confirmé !\n"); else free(aux->tabDept[pos]); + decalageGaucheDept(aux->tabDept, pos, aux->nbChoix); aux->nbChoix = aux->nbChoix - 1; if (aux->nbChoix == 0) suppressionCandid(tcandid[iCandid]->idCandIUT, ville, aux->tabDept, aux->nbChoix); @@ -1268,8 +1310,10 @@ void modifCandid(Candidat **tcandid, int nbCandid, VilleIUT **tiut, int nbIUT, i switch(choix){ case 1: ajouterDept(tcandid, nbCandid, tiut, nbIUT, iCandid); + break; case 2: supprimerCandidDept(tcandid, nbCandid, tiut, nbIUT, iCandid); + break; case 9: return; } diff --git a/SAE.h b/SAE.h index 0520e40..f2168b7 100644 --- a/SAE.h +++ b/SAE.h @@ -228,4 +228,8 @@ void SauvegardeCandid(Candidat **tabC, int nbCandid); void SauvegarderCandidIUT(ListeCandid l, FILE *flot); -void SauvegardeCandidDept(ChoixDept **tDept, int nbDept, FILE *flot); \ No newline at end of file +void SauvegardeCandidDept(ChoixDept **tDept, int nbDept, FILE *flot); + +void decalageGauche(Candidat **tab,int pos, int nbEle); + +void decalageGaucheDept(ChoixDept **tab, int pos, int nbEle); \ No newline at end of file diff --git a/candidature.txt b/candidature.txt index bda90a3..0341a4d 100644 --- a/candidature.txt +++ b/candidature.txt @@ -13,7 +13,7 @@ Réseaux 0 Lyon 1 -Jeu-vidéos +Jeux-videos 0 0 2