correction bug mais il en reste sur le chargement

master
Alexis LAURENT 2 years ago
parent 34a7688c28
commit 7e179615d5

97
SAE.c

@ -207,6 +207,12 @@ void global(void)
tab = chargementVille(nomFich,30,&tailleL);
printf("\n");
gestionMenu(tab, tailleL);*/
int tphys, nb;
Candidat **tab;
tab = chargmentCandid("candidature.txt", &tphys, &nb);
afficherCandid(tab[0]->idCandIUT);
}
void AffichageVille(VilleIUT **tiut, int nbEle)
@ -570,7 +576,7 @@ ListeCandid ListeCandidvide(void)
return NULL;
}
ListeCandid insererEnTeteCandid(ListeCandid l, char *ville, ChoixDept **tDept)
ListeCandid insererEnTeteCandid(ListeCandid l, char *ville, ChoixDept **tDept, int nbEle)
{
MaillonCandid *m;
m = (MaillonCandid *)malloc(sizeof(MaillonCandid));
@ -580,19 +586,21 @@ ListeCandid insererEnTeteCandid(ListeCandid l, char *ville, ChoixDept **tDept)
exit(1);
}
strcpy(m->iutCandid, ville);
m->nbChoix = nbEle;
m->tabDept = tDept;
m->suiv = l;
return m;
}
ListeCandid insererCandid(ListeCandid l, char *ville, ChoixDept **tDept)
ListeCandid insererCandid(ListeCandid l, char *ville, ChoixDept **tDept, int nbEle)
{
if (l == NULL)
return insererEnTeteCandid(l, ville, tDept, tailleP);
return insererEnTeteCandid(l, ville, tDept, nbEle);
if (strcmp(ville, l->iutCandid) < 0)
return insererEnTeteCandid(l, ville, tDept, tailleP);
return insererEnTeteCandid(l, ville, tDept, nbEle);
if (strcmp(ville, l->iutCandid) == 0)
return l;
l->suiv = insererCandid(l->suiv, ville, tDept, tailleP);
l->suiv = insererCandid(l->suiv, ville, tDept, nbEle);
return l;
}
@ -602,12 +610,12 @@ int rechCandiDept(ChoixDept **tDept, int tailleL, char dept[], int *trouve)
while(inf <= sup)
{
m = (inf + sup)/2;
if (strcmp(*(tDept[m]).departement, dept)==0)
if (strcmp(tDept[m]->departement, dept)==0)
{
*trouve = 1;
return m;
}
if (strcmp(*(tDept[m]).departement, dept)>0)
if (strcmp(tDept[m]->departement, dept)<0)
sup = m-1;
else inf = m+1;
}
@ -620,7 +628,7 @@ int plusGrandCandidDept(ChoixDept **tDept, int tailleL)
int pge = 0, i;
for (i = 1; i < tailleL; i++)
{
if(strcmp(*(tDept[i].departement), *(tDept[pge].departement))>0)
if(strcmp(tDept[i]->departement, tDept[pge]->departement)>0)
pge = i;
return pge;
}
@ -640,41 +648,35 @@ void triEchangeCandidDept(ChoixDept **tDept, int tailleL)
while(tailleL > 1)
{
pge = plusGrandCandidDept(tDept, tailleL);
echangerCandidDept(tDept, pge, tailleL - 1)
tailleL = tailleL - 1
echangerCandidDept(tDept, pge, tailleL - 1);
tailleL = tailleL - 1;
}
}
ChoixDept ** insererTDept(ChoixDept **tDept, int *tailleP, int *tailleL ,char dept[], int deciDept, int deciCandid)
ChoixDept ** insererTDept(ChoixDept **tDept, int tailleP, int tailleL ,char dept[], int deciDept, int deciCandid)
{
ChoixDept **aux;
aux = tDept;
int trouve;
if (*tailleL == *tailleP)
int trouve, pos;
printf("1");
if (tailleL == tailleP)
{
*tailleP = *tailleP + 10;
aux = (ChoixDept **)realloc(tDept, *tailleP + 1 * sizeof(ChoixDept *));
aux = (ChoixDept **)realloc(tDept, (tailleP + 1) * sizeof(ChoixDept *));
if (aux == NULL)
{
printf("pb réalloc\n");
exit(1);
}
}
pos = rechCandiDept(tDept, *tailleL, dept, &trouve);
if (trouve == 1)
{
printf("Departement déjà dans le tableau");
return aux;
}
triEchangeCandidDept(tDept, tailleL)
strcpy(*(aux[pos]).departement, dept);
*(aux[pos]).decisionDept = deciDept;
*(aux[pos]).decisionCandid = deciCandid;
*tailleL = *tailleL + 1;
printf("2");
strcpy(aux[tailleL]->departement, dept);
aux[tailleL]->decisionDept = deciDept;
aux[tailleL]->decisionCandid = deciCandid;
printf("%s %d %d", aux[tailleL]->departement, aux[tailleL]->decisionDept, aux[tailleL]->decisionCandid);
return aux;
}
void videTabDept(ChoixDept **tDept, int *tailleP)
void videTabDept(ChoixDept **tDept, int tailleP)
{
ChoixDept *aux;
int i;
@ -683,10 +685,9 @@ void videTabDept(ChoixDept **tDept, int *tailleP)
aux = tDept[i];
free(aux);
}
*tailleP = 0;
}
ListeCandid suppressionEnTeteCandid(ListeCandid l , ChoixDept **tDept, int *tailleP)
ListeCandid suppressionEnTeteCandid(ListeCandid l , ChoixDept **tDept, int tailleP)
{
MaillonCandid *aux;
if(l == NULL)
@ -701,7 +702,7 @@ ListeCandid suppressionEnTeteCandid(ListeCandid l , ChoixDept **tDept, int *tail
return l;
}
ListeCandid suppressionCandid(ListeCandid l, char *ville, ChoixDept **tDept, int *tailleP)
ListeCandid suppressionCandid(ListeCandid l, char *ville, ChoixDept **tDept, int tailleP)
{
if (l == NULL)
return l;
@ -713,7 +714,7 @@ ListeCandid suppressionCandid(ListeCandid l, char *ville, ChoixDept **tDept, int
return l;
}
void afficherCandid(ListeCandid l,int tailleL)
void afficherCandid(ListeCandid l)
{
MaillonCandid *aux;
int i;
@ -721,8 +722,8 @@ void afficherCandid(ListeCandid l,int tailleL)
while(aux != NULL)
{
printf("%s\t",aux->iutCandid);
for (i = 0; i < tailleL;i++)
printf("%s %d %d\n", aux->idCandIUT.*(tDept[i]).departement, aux->idCandIUT.*(tDept[i]).decisionDept, aux->idCandIUT.*(tDept[i]).decisionCandid);
for (i = 0; i < aux->nbChoix;i++)
printf("%s %d %d\n", aux->tabDept[i]->departement, aux->tabDept[i]->decisionDept, aux->tabDept[i]->decisionCandid);
aux = aux->suiv;
}
printf("\n");
@ -737,7 +738,7 @@ int longueur(ListeCandid l)
Candidat **chargmentCandid(char *nomFich, int *tphys, int *tailleL)
{
int i = 0, j = 0, nbIUT, nbDept;
int i = 0, nbIUT, nbDept;
FILE *flot;
Candidat **tcandid;
ChoixDept **tDept;
@ -767,6 +768,7 @@ Candidat **chargmentCandid(char *nomFich, int *tphys, int *tailleL)
while(!feof(flot))
{
fscanf(flot, "%d", &nbIUT);
printf("%d\n", nbIUT);
tcandid[*tailleL]->idCandIUT = ListeCandidvide();
while(i < nbIUT)
{
@ -797,32 +799,45 @@ Candidat lireCandidat(FILE *flot)
fscanf(flot,"%s%*c",c.nom);
fgets(c.prenom,30,flot);
c.prenom[strlen(c.prenom) - 1] = '\0';
fscanf(flot, "%f %f %f %f", &c.note[0], &c.note[1], &c.note[2], &c.note[3]);
printf("%d %s %s %.1f %.1f %.1f %.1f\n", c.id, c.nom, c.prenom, c.note[0], c.note[1], c.note[2], c.note[3]);
return c;
}
ListeCandid traiterCandidIUT(ListeCandid l, FILE *flot)
{
char ville[30];
int nbDept, i;
int nbDept, i=0;
ChoixDept **tDept;
fscanf(flot,"%s",ville);
fscanf(flot, "%d", &nbDept);
printf("%s |%d|\n", ville, nbDept);
tDept = (ChoixDept **)malloc(sizeof(ChoixDept *)*nbDept);
if(tDept == NULL)
{
printf("Pb malloc candidIUt\n");
exit(1);
}
while (i < nbDept)
{
tDept = traiterCandidDept(tDept, i, nbDept, *flot);
tDept = traiterCandidDept(tDept, i, nbDept, flot);
i = i + 1;
}
l = insererCandid(l , ville , tDept);
printf("\n %s \n",l->iutCandid);
l = insererCandid(l , ville , tDept, nbDept);
return l;
}
ChoixDept **traiterCandidDept(ChoixDept **tDept,int *tailleL, int *tailleP, FILE *flot)
ChoixDept **traiterCandidDept(ChoixDept **tDept,int tailleL, int tailleP, FILE *flot)
{
char dept[30];
int deciDept, deciCandid;
fscanf(flot,"%s%*c", dept);
fscanf(flot,"%d %d", &deciDept, &deciCandid);
fscanf(flot,"%s", dept);
fscanf(flot,"%d", &deciDept);
fscanf(flot,"%d",&deciCandid);
printf("|%s %d %d|\n", dept, deciDept, deciCandid);
printf("a");
tDept = insererTDept(tDept, tailleP, tailleL , dept, deciDept, deciCandid);
printf("1");
return tDept;
}

17
SAE.h

@ -34,6 +34,7 @@ typedef struct
typedef struct maillonEtu
{
char iutCandid[30];
int nbChoix;
ChoixDept **tabDept;
struct maillonEtu *suiv;
}MaillonCandid, *ListeCandid;
@ -131,9 +132,9 @@ void SauvegarderListe(ListeDept l, FILE* flot);
ListeCandid ListeCandidvide(void);
ListeCandid insererEnTeteCandid(ListeCandid l, char *ville, ChoixDept **tDept);
ListeCandid insererEnTeteCandid(ListeCandid l, char *ville, ChoixDept **tDept, int nbEle);
ListeCandid insererCandid(ListeCandid l, char *ville, ChoixDept **tDept);
ListeCandid insererCandid(ListeCandid l, char *ville, ChoixDept **tDept, int nbEle);
int rechCandiDept(ChoixDept **tDept, int tailleL, char dept[], int *trouve);
@ -143,15 +144,15 @@ void echangerCandidDept(ChoixDept **tDept, int i, int j);
void triEchangeCandidDept(ChoixDept **tDept, int tailleL);
ChoixDept ** insererTDept(ChoixDept **tDept, int *tailleP, int *tailleL ,char dept[], int deciDept, int deciCandid);
ChoixDept ** insererTDept(ChoixDept **tDept, int tailleP, int tailleL ,char dept[], int deciDept, int deciCandid);
void videTabDept(ChoixDept **tDept, int *tailleP);
void videTabDept(ChoixDept **tDept, int tailleP);
ListeCandid suppressionEnTeteCandid(ListeCandid l , ChoixDept **tDept, int *tailleP);
ListeCandid suppressionEnTeteCandid(ListeCandid l , ChoixDept **tDept, int tailleP);
isteCandid suppressionCandid(ListeCandid l, char *ville, ChoixDept **tDept, int *tailleP);
ListeCandid suppressionCandid(ListeCandid l, char *ville, ChoixDept **tDept, int tailleP);
void afficherCandid(ListeCandid l,int tailleL);
void afficherCandid(ListeCandid l);
int longueur(ListeCandid l);
@ -161,4 +162,4 @@ Candidat lireCandidat(FILE *flot);
ListeCandid traiterCandidIUT(ListeCandid l, FILE *flot);
ChoixDept **traiterCandidDept(ChoixDept **tDept,int *tailleL, int *tailleP, FILE *flot);
ChoixDept **traiterCandidDept(ChoixDept **tDept,int tailleL, int tailleP, FILE *flot);
Loading…
Cancel
Save