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

17
SAE.h

@ -34,6 +34,7 @@ typedef struct
typedef struct maillonEtu typedef struct maillonEtu
{ {
char iutCandid[30]; char iutCandid[30];
int nbChoix;
ChoixDept **tabDept; ChoixDept **tabDept;
struct maillonEtu *suiv; struct maillonEtu *suiv;
}MaillonCandid, *ListeCandid; }MaillonCandid, *ListeCandid;
@ -131,9 +132,9 @@ void SauvegarderListe(ListeDept l, FILE* flot);
ListeCandid ListeCandidvide(void); 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); 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); 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); int longueur(ListeCandid l);
@ -161,4 +162,4 @@ Candidat lireCandidat(FILE *flot);
ListeCandid traiterCandidIUT(ListeCandid l, 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