Correction de toutes les fonctions sauf la sauvegarde Candidature

master
Alexis LAURENT 2 years ago
parent 7764dc2747
commit 1a275149ed

62
SAE.c

@ -919,6 +919,13 @@ ListeCandid rechCandidIUT(ListeCandid l, char *code)
return rechCandidIUT(l->suiv, 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) void supprimerCandid(Candidat **tab, int *nbEle)
{ {
int idSup, pos, trouve; 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); suppressionCandid(tab[pos]->idCandIUT, tab[pos]->idCandIUT->iutCandid, tab[pos]->idCandIUT->tabDept, tab[pos]->idCandIUT->nbChoix);
tab[pos]->idCandIUT = tab[pos]->idCandIUT->suiv; tab[pos]->idCandIUT = tab[pos]->idCandIUT->suiv;
} }
*nbEle = *nbEle - 1;
free(tab[pos]); free(tab[pos]);
triEchangecandid(tab, *nbEle + 1); decalageGauche(tab, pos, *nbEle);
*nbEle = *nbEle - 1;
return; return;
if(!verifSelection()) 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) : "); printf("voulez vous faire votre choix maintenant (oui|non) : ");
scanf("%s", choix); scanf("%s", choix);
if (strcmp(choix, "oui")==0) if (strcmp(choix, "oui")==0)
modifCandid(tcandid, *nbCandid, tiut, 0, c.id); modifCandid(tcandid, *nbCandid, tiut, 0, *nbCandid - 1);
if (strcmp(choix, "non")==0) if (strcmp(choix, "non")==0)
break; break;
return; return;
@ -1076,7 +1083,7 @@ void gestionCandid(VilleIUT **tiut, int nbIUT, Candidat **tcandid, int *nbCandid
if (trouve == 0) if (trouve == 0)
printf("identifiant pas présent dans la base de donnée !\n"); printf("identifiant pas présent dans la base de donnée !\n");
else else
modifCandid(tcandid, *nbCandid, tiut, nbIUT, id); modifCandid(tcandid, *nbCandid, tiut, nbIUT, pos);
system("clear"); system("clear");
break; break;
case 4: case 4:
@ -1139,6 +1146,7 @@ int recherchecandidDept(ChoixDept **tab,int nbEle, char code[],int *trouve)
*trouve = 1; *trouve = 1;
return i; return i;
} }
i = i + 1;
} }
*trouve = 0; *trouve = 0;
return -1; return -1;
@ -1159,6 +1167,7 @@ void ajouterDept(Candidat **tcandid, int nbCandid, VilleIUT **tiut, int nbIUT, i
{ {
char ville[30], departement[30]; char ville[30], departement[30];
int pos,irech, trouve; int pos,irech, trouve;
MaillonDept *auxD;
MaillonCandid *aux; MaillonCandid *aux;
aux = (MaillonCandid *)malloc(sizeof(MaillonCandid)); aux = (MaillonCandid *)malloc(sizeof(MaillonCandid));
if (aux == NULL) 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 : "); printf("Dans quel Département voulez-vous candidater : ");
scanf("%s%*c", departement); 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"); 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); aux = recherchecandidIUT(tcandid[iCandid]->idCandIUT, ville);
printf("2\n");
if (aux == NULL) if (aux == NULL)
{ {
tDept = (ChoixDept **)malloc(sizeof(ChoixDept *)*10); printf("3\n");
tDept = (ChoixDept **)malloc(10 * sizeof(ChoixDept *));
printf("4\n");
if(tDept == NULL) if(tDept == NULL)
{ {
printf("Pb malloc candidIUt\n"); printf("Pb malloc candidIUt\n");
exit(1); 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); *(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); tcandid[iCandid]->idCandIUT = insererCandid(tcandid[iCandid]->idCandIUT, ville, tDept, 1);
printf("Candidature Validée \n"); printf("Candidature Validée \n");
} }
else if (aux != NULL)
{ {
printf("3\n");
irech = recherchecandidDept(aux->tabDept, aux->nbChoix, departement, &trouve); irech = recherchecandidDept(aux->tabDept, aux->nbChoix, departement, &trouve);
printf("4\n");
if (irech == -1) 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); *(aux->tabDept[aux->nbChoix]) = RempTabCandid(departement, 0, 0);
printf("6\n");
aux->nbChoix = aux->nbChoix + 1; aux->nbChoix = aux->nbChoix + 1;
strcpy(aux->iutCandid, ville);
printf("Candidature validée !\n"); printf("Candidature validée !\n");
} }
else else
@ -1219,7 +1253,14 @@ void ajouterDept(Candidat **tcandid, int nbCandid, VilleIUT **tiut, int nbIUT, i
if(!verifSelection()) if(!verifSelection())
break; 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) 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"); printf("Annulation confirmé !\n");
else else
free(aux->tabDept[pos]); free(aux->tabDept[pos]);
decalageGaucheDept(aux->tabDept, pos, aux->nbChoix);
aux->nbChoix = aux->nbChoix - 1; aux->nbChoix = aux->nbChoix - 1;
if (aux->nbChoix == 0) if (aux->nbChoix == 0)
suppressionCandid(tcandid[iCandid]->idCandIUT, ville, aux->tabDept, aux->nbChoix); 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){ switch(choix){
case 1: case 1:
ajouterDept(tcandid, nbCandid, tiut, nbIUT, iCandid); ajouterDept(tcandid, nbCandid, tiut, nbIUT, iCandid);
break;
case 2: case 2:
supprimerCandidDept(tcandid, nbCandid, tiut, nbIUT, iCandid); supprimerCandidDept(tcandid, nbCandid, tiut, nbIUT, iCandid);
break;
case 9: case 9:
return; return;
} }

@ -229,3 +229,7 @@ void SauvegardeCandid(Candidat **tabC, int nbCandid);
void SauvegarderCandidIUT(ListeCandid l, FILE *flot); void SauvegarderCandidIUT(ListeCandid l, FILE *flot);
void SauvegardeCandidDept(ChoixDept **tDept, int nbDept, FILE *flot); void SauvegardeCandidDept(ChoixDept **tDept, int nbDept, FILE *flot);
void decalageGauche(Candidat **tab,int pos, int nbEle);
void decalageGaucheDept(ChoixDept **tab, int pos, int nbEle);

@ -13,7 +13,7 @@ Réseaux
0 0
Lyon Lyon
1 1
Jeu-vidéos Jeux-videos
0 0
0 0
2 2

Loading…
Cancel
Save