modif struct

master
Alexis LAURENT 2 years ago
parent 4a58838cca
commit 34a7688c28

280
SAE.c

@ -207,25 +207,6 @@ void global(void)
tab = chargementVille(nomFich,30,&tailleL); tab = chargementVille(nomFich,30,&tailleL);
printf("\n"); printf("\n");
gestionMenu(tab, tailleL);*/ gestionMenu(tab, tailleL);*/
int tailleL, i = 0;
Candidat** tab;
char nomFich[20];
strcpy(nomFich,"candidature.txt");
printf("charg\n");
tab = chargmentCandid(nomFich, 30, &tailleL);
printf("\n");
while(i < 4)
{
printf("%d %s %s\t",tab[i]->id, tab[i]->idCandIUT->iutCandid, tab[i]->idCandIUT->idCandDept->departement);
i = i + 1;
printf("\n");
afficherCandid(tab[i]->idCandIUT);
}
//tab[0]->idCandIUT = tab[0]->idCandIUT->suiv;
//printf("%s\n", tab[0]->idCandIUT->iutCandid);
tab[0]->idCandIUT->idCandDept = tab[0]->idCandIUT->idCandDept->suiv;
printf("%s\n", tab[0]->idCandIUT->idCandDept->departement);
} }
void AffichageVille(VilleIUT **tiut, int nbEle) void AffichageVille(VilleIUT **tiut, int nbEle)
@ -563,7 +544,7 @@ int plusGrand(VilleIUT **tiut, int nbEle)
int pge = 0, i; int pge = 0, i;
for (i = 1; i < nbEle; i++) for (i = 1; i < nbEle; i++)
if (strcmp(tiut[i]->ville,tiut[pge]->ville)>0) if (strcmp(tiut[i]->ville,tiut[pge]->ville)>0)
pge = 1; pge = i;
return pge; return pge;
} }
@ -575,42 +556,6 @@ void echanger(VilleIUT **tiut, int i, int j)
tiut[j] = aux; tiut[j] = aux;
} }
int longueurListe(ListeDept l)
{
int cpt = 0;
while (l != NULL)
{
cpt += 1;
l = l->suiv;
}
return cpt;
}
void SauvegarderIUT(VilleIUT** tabV, int tailleL) {
int i, nbDept;
FILE* flot;
flot = fopen("res.txt","w");
for (i = 0 ; i < tailleL ; i++) {
fprintf(flot,"%s\n",tabV[i]->ville);
nbDept = longueurListe(tabV[i]->idDept);
fprintf(flot,"%d\n",&nbDept);
SauvegarderListe(tabV[i]->idDept,flot);
free(tabV[i]);
}
}
void SauvegarderListe(ListeDept l, FILE* flot) {
MaillonDept* tmp;
while (l->suiv != NULL) {
tmp = l;
fprintf(flot,"%s %d %s\n",l->departement,l->nbPers,l->responsable);
l = l->suiv;
free(tmp);
}
fprintf(flot,"%s %d %s\n",l->departement,l->nbPers,l->responsable);
free(l);
}
void clearpage(void) void clearpage(void)
{ {
@ -625,93 +570,123 @@ ListeCandid ListeCandidvide(void)
return NULL; return NULL;
} }
ListeCandidDept ListeCandidDeptvide(void) ListeCandid insererEnTeteCandid(ListeCandid l, char *ville, ChoixDept **tDept)
{
return NULL;
}
ListeCandidDept insererEnTeteCandidDept(ListeCandidDept l, char departement[], int deciDept, int deciCandid)
{ {
MaillonCandidDept *m; MaillonCandid *m;
m = (MaillonCandidDept *)malloc(sizeof(MaillonCandidDept)); m = (MaillonCandid *)malloc(sizeof(MaillonCandid));
if (m == NULL) if (m == NULL)
{ {
printf("Pb maillon"); printf("Pb maillon");
exit(1); exit(1);
} }
strcpy(m->departement, departement); strcpy(m->iutCandid, ville);
m->decisionDept = deciDept;
m->decisionCandid = deciCandid;
m->suiv = l; m->suiv = l;
return m; return m;
} }
ListeCandidDept insererCandidDept(ListeCandidDept l, char departement[], int deciDept, int deciCandid) ListeCandid insererCandid(ListeCandid l, char *ville, ChoixDept **tDept)
{ {
if (l == NULL) if (l == NULL)
return insererEnTeteCandidDept(l, departement, deciDept, deciCandid); return insererEnTeteCandid(l, ville, tDept, tailleP);
if (strcmp(departement, l->departement) < 0) if (strcmp(ville, l->iutCandid) < 0)
return insererEnTeteCandidDept(l, departement, deciDept, deciCandid); return insererEnTeteCandid(l, ville, tDept, tailleP);
if (strcmp(departement, l->departement) == 0) if (strcmp(ville, l->iutCandid) == 0)
return l; return l;
l->suiv = insererCandidDept(l->suiv, departement, deciDept, deciCandid); l->suiv = insererCandid(l->suiv, ville, tDept, tailleP);
return l; return l;
}
int rechCandiDept(ChoixDept **tDept, int tailleL, char dept[], int *trouve)
{
int inf = 0, sup = tailleL + 1, m;
while(inf <= sup)
{
m = (inf + sup)/2;
if (strcmp(*(tDept[m]).departement, dept)==0)
{
*trouve = 1;
return m;
}
if (strcmp(*(tDept[m]).departement, dept)>0)
sup = m-1;
else inf = m+1;
}
*trouve = 0;
return inf;
} }
ListeCandid insererEnTeteCandid(ListeCandid l, char *ville) int plusGrandCandidDept(ChoixDept **tDept, int tailleL)
{ {
MaillonCandid *m; int pge = 0, i;
m = (MaillonCandid *)malloc(sizeof(MaillonCandid)); for (i = 1; i < tailleL; i++)
if (m == NULL)
{ {
printf("Pb maillon"); if(strcmp(*(tDept[i].departement), *(tDept[pge].departement))>0)
exit(1); pge = i;
return pge;
} }
strcpy(m->iutCandid, ville);
m->suiv = l;
return m;
} }
ListeCandid insererCandid(ListeCandid l, char *ville) void echangerCandidDept(ChoixDept **tDept, int i, int j)
{ {
if (l == NULL) ChoixDept *aux;
return insererEnTeteCandid(l, ville); aux = tDept[i];
if (strcmp(ville, l->iutCandid) < 0) tDept[i] = tDept[j];
return insererEnTeteCandid(l, ville); tDept[j] = aux;
if (strcmp(ville, l->iutCandid) == 0)
return l;
l->suiv = insererCandid(l->suiv, ville);
return l;
} }
ListeCandidDept suppressionEnTeteCandidDept(ListeCandidDept l) void triEchangeCandidDept(ChoixDept **tDept, int tailleL)
{ {
MaillonCandidDept *aux; int pge;
if(l == NULL) while(tailleL > 1)
{ {
printf("opération interdite !\n"); pge = plusGrandCandidDept(tDept, tailleL);
exit(1); echangerCandidDept(tDept, pge, tailleL - 1)
tailleL = tailleL - 1
} }
aux = l;
l = l->suiv;
free(aux);
return l;
} }
ListeCandidDept suppressionCandidDept(ListeCandidDept l, char *departement) ChoixDept ** insererTDept(ChoixDept **tDept, int *tailleP, int *tailleL ,char dept[], int deciDept, int deciCandid)
{ {
if (l == NULL) ChoixDept **aux;
return l; aux = tDept;
if (strcmp(departement, l->departement) < 0) int trouve;
return l; if (*tailleL == *tailleP)
if (strcmp(departement, l->departement) == 0) {
return suppressionEnTeteCandidDept(l); *tailleP = *tailleP + 10;
l->suiv = suppressionCandidDept(l->suiv, departement); aux = (ChoixDept **)realloc(tDept, *tailleP + 1 * sizeof(ChoixDept *));
return l; 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;
return aux;
} }
ListeCandid suppressionEnTeteCandid(ListeCandid l) void videTabDept(ChoixDept **tDept, int *tailleP)
{
ChoixDept *aux;
int i;
for (i=tailleP - 1; i >= 0; i--)
{
aux = tDept[i];
free(aux);
}
*tailleP = 0;
}
ListeCandid suppressionEnTeteCandid(ListeCandid l , ChoixDept **tDept, int *tailleP)
{ {
MaillonCandid *aux; MaillonCandid *aux;
if(l == NULL) if(l == NULL)
@ -720,51 +695,34 @@ ListeCandid suppressionEnTeteCandid(ListeCandid l)
exit(1); exit(1);
} }
aux = l; aux = l;
videTabDept(tDept, tailleP);
l = l->suiv; l = l->suiv;
free(aux); free(aux);
return l; return l;
} }
ListeCandid suppressionCandid(ListeCandid l, char *ville) ListeCandid suppressionCandid(ListeCandid l, char *ville, ChoixDept **tDept, int *tailleP)
{ {
if (l == NULL) if (l == NULL)
return l; return l;
if (strcmp(ville, l->iutCandid) < 0) if (strcmp(ville, l->iutCandid) < 0)
return l; return l;
if (strcmp(ville, l->iutCandid) == 0) if (strcmp(ville, l->iutCandid) == 0)
{ return suppressionEnTeteCandid(l, tDept, tailleP);
while (1) l->suiv = suppressionCandid(l->suiv, ville, tDept, tailleP);
{
if (l->idCandDept == NULL)
break;
suppressionEnTeteCandidDept(l->idCandDept);
}
return suppressionEnTeteCandid(l);
}
l->suiv = suppressionCandid(l->suiv, ville);
return l; return l;
} }
void afficherCandidDept(ListeCandidDept l) void afficherCandid(ListeCandid l,int tailleL)
{
MaillonCandidDept *aux;
aux = l;
while(aux != NULL)
{
printf("%s\t%d\t%d\n",aux->departement, aux->decisionDept, aux->decisionCandid);
aux = aux->suiv;
}
printf("\n");
}
void afficherCandid(ListeCandid l)
{ {
MaillonCandid *aux; MaillonCandid *aux;
int i;
aux = l; aux = l;
while(aux != NULL) while(aux != NULL)
{ {
printf("%s\t",aux->iutCandid); printf("%s\t",aux->iutCandid);
afficherCandidDept(aux->idCandDept); 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);
aux = aux->suiv; aux = aux->suiv;
} }
printf("\n"); printf("\n");
@ -777,23 +735,26 @@ int longueur(ListeCandid l)
return 1 + longueur(l->suiv); return 1 + longueur(l->suiv);
} }
Candidat **chargmentCandid(char *nomFich, int tphys, int *tailleL) Candidat **chargmentCandid(char *nomFich, int *tphys, int *tailleL)
{ {
int i = 0, j = 0, nbCandidat, nbIUT, nbDept; int i = 0, j = 0, nbIUT, nbDept;
FILE *flot; FILE *flot;
Candidat **tcandid; Candidat **tcandid;
tcandid = (Candidat **)malloc(sizeof(Candidat *) * tphys); ChoixDept **tDept;
if (tcandid == NULL)
{
printf("Erreur malloc tcandid !\n");
exit(1);
}
flot = fopen(nomFich, "r"); flot = fopen(nomFich, "r");
if (flot == NULL) if (flot == NULL)
{ {
printf("Problèmes d'ouverture de fichier !\n"); printf("Problèmes d'ouverture de fichier !\n");
exit(1); exit(1);
} }
fscanf(flot,"%d",tphys);
*tphys = *tphys + 10;
tcandid = (Candidat **)malloc(sizeof(Candidat *) * *tphys);
if (tcandid == NULL)
{
printf("Erreur malloc tcandid !\n");
exit(1);
}
*tailleL = 0; *tailleL = 0;
tcandid[*tailleL] = (Candidat *)malloc(sizeof(Candidat)); tcandid[*tailleL] = (Candidat *)malloc(sizeof(Candidat));
if (tcandid[*tailleL] == NULL) if (tcandid[*tailleL] == NULL)
@ -802,7 +763,6 @@ Candidat **chargmentCandid(char *nomFich, int tphys, int *tailleL)
fclose(flot); fclose(flot);
exit(1); exit(1);
} }
fscanf(flot,"%d",&nbCandidat);
*(tcandid[*tailleL]) = lireCandidat(flot); *(tcandid[*tailleL]) = lireCandidat(flot);
while(!feof(flot)) while(!feof(flot))
{ {
@ -811,14 +771,6 @@ Candidat **chargmentCandid(char *nomFich, int tphys, int *tailleL)
while(i < nbIUT) while(i < nbIUT)
{ {
tcandid[*tailleL]->idCandIUT = traiterCandidIUT(tcandid[*tailleL]->idCandIUT, flot); tcandid[*tailleL]->idCandIUT = traiterCandidIUT(tcandid[*tailleL]->idCandIUT, flot);
fscanf(flot, "%d", &nbDept);
tcandid[*tailleL]->idCandIUT->idCandDept = ListeCandidDeptvide();
while(j < nbDept)
{
tcandid[*tailleL]->idCandIUT->idCandDept = traiterCandidDept(tcandid[*tailleL]->idCandIUT->idCandDept, flot);
j = j + 1;
}
j = 0;
i = i + 1; i = i + 1;
} }
i = 0; i = 0;
@ -845,26 +797,32 @@ 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 %f %f %f %f\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;
fscanf(flot,"%s",ville); fscanf(flot,"%s",ville);
l = insererCandid(l , ville); fscanf(flot, "%d", &nbDept);
tDept = (ChoixDept **)malloc(sizeof(ChoixDept *)*nbDept);
while (i < nbDept)
{
tDept = traiterCandidDept(tDept, i, nbDept, *flot);
i = i + 1;
}
l = insererCandid(l , ville , tDept);
printf("\n %s \n",l->iutCandid); printf("\n %s \n",l->iutCandid);
return l; return l;
} }
ListeCandidDept traiterCandidDept(ListeCandidDept l, FILE *flot) ChoixDept **traiterCandidDept(ChoixDept **tDept,int *tailleL, int *tailleP, FILE *flot)
{ {
char departement[30]; char dept[30];
int deciDept, deciCandid; int deciDept, deciCandid;
fscanf(flot,"%s %d %d",departement, &deciDept, &deciCandid); fscanf(flot,"%s%*c", dept);
l = insererCandidDept(l, departement, deciDept, deciCandid); fscanf(flot,"%d %d", &deciDept, &deciCandid);
printf("\n %s %d %d \n", l->departement, l->decisionDept, l->decisionCandid); tDept = insererTDept(tDept, tailleP, tailleL , dept, deciDept, deciCandid);
return l; return tDept;
} }

34
SAE.h

@ -24,22 +24,20 @@ typedef struct
//######################################### //#########################################
//######################################### //#########################################
typedef struct maillonCandidDept typedef struct
{ {
char departement[30]; char departement[30];
int decisionDept; int decisionDept;
int decisionCandid; int decisionCandid;
struct maillonCandidDept *suiv; }ChoixDept;
}MaillonCandidDept, *ListeCandidDept;
typedef struct maillonEtu typedef struct maillonEtu
{ {
char iutCandid[30]; char iutCandid[30];
MaillonCandidDept *idCandDept; ChoixDept **tabDept;
struct maillonEtu *suiv; struct maillonEtu *suiv;
}MaillonCandid, *ListeCandid; }MaillonCandid, *ListeCandid;
typedef struct typedef struct
{ {
int id; int id;
@ -133,34 +131,34 @@ void SauvegarderListe(ListeDept l, FILE* flot);
ListeCandid ListeCandidvide(void); ListeCandid ListeCandidvide(void);
ListeCandidDept ListeCandidDeptvide(void); ListeCandid insererEnTeteCandid(ListeCandid l, char *ville, ChoixDept **tDept);
ListeCandidDept insererEnTeteCandidDept(ListeCandidDept l, char departement[], int deciDept, int deciCandid); ListeCandid insererCandid(ListeCandid l, char *ville, ChoixDept **tDept);
ListeCandidDept insererCandidDept(ListeCandidDept l, char departement[], int deciDept, int deciCandid); int rechCandiDept(ChoixDept **tDept, int tailleL, char dept[], int *trouve);
ListeCandid insererEnTeteCandid(ListeCandid l, char *ville); int plusGrandCandidDept(ChoixDept **tDept, int tailleL);
ListeCandid insererCandid(ListeCandid l, char *ville); void echangerCandidDept(ChoixDept **tDept, int i, int j);
ListeCandidDept suppressionEnTeteCandidDept(ListeCandidDept l); void triEchangeCandidDept(ChoixDept **tDept, int tailleL);
ListeCandidDept suppressionCandidDept(ListeCandidDept l, char *departement); ChoixDept ** insererTDept(ChoixDept **tDept, int *tailleP, int *tailleL ,char dept[], int deciDept, int deciCandid);
ListeCandid suppressionEnTeteCandid(ListeCandid l); void videTabDept(ChoixDept **tDept, int *tailleP);
ListeCandid suppressionCandid(ListeCandid l, char *ville); ListeCandid suppressionEnTeteCandid(ListeCandid l , ChoixDept **tDept, int *tailleP);
void afficherCandidDept(ListeCandidDept l); isteCandid suppressionCandid(ListeCandid l, char *ville, ChoixDept **tDept, int *tailleP);
void afficherCandid(ListeCandid l); void afficherCandid(ListeCandid l,int tailleL);
int longueur(ListeCandid l); int longueur(ListeCandid l);
Candidat **chargmentCandid(char *nomFich, int tphys, int *tailleL); Candidat **chargmentCandid(char *nomFich, int *tphys, int *tailleL);
Candidat lireCandidat(FILE *flot); Candidat lireCandidat(FILE *flot);
ListeCandid traiterCandidIUT(ListeCandid l, FILE *flot); ListeCandid traiterCandidIUT(ListeCandid l, FILE *flot);
ListeCandidDept traiterCandidDept(ListeCandidDept l, FILE *flot); ChoixDept **traiterCandidDept(ChoixDept **tDept,int *tailleL, int *tailleP, FILE *flot);

@ -1,33 +1,57 @@
4 4
1 1
Paul Bocluse Paul
Bocluse
14 9 7 18 14 9 7 18
2 2
Clermont-Ferrand Clermont-Ferrand
2 2
Informatique 0 0 Informatique
Réseaux 0 0 0
0
Réseaux
0
0
Lyon Lyon
1 1
Jeu-vidéos 0 0 Jeu-vidéos
0
0
2 2
Sam Hirrite Sam
Hirrite
17 17 14 11 17 17 14 11
1 1
Lyon Lyon
1 1
GEA 0 0 GEA
0
0
3 3
Guy Alone Guy
11 9 4 8 Alone
1 11 9.5 4.7 8.9
2
Clermont-Ferrand Clermont-Ferrand
1 1
Réseaux 0 0 Réseaux
0
0
Lyon
1
GEA
0
0
4 4
Don Qui Roté Don
Qui Roté
14 5 9 12 14 5 9 12
1 1
Clermont-Ferrand Clermont-Ferrand
1 2
Informatique 0 0 Informatique
0
0
Réseaux
0
0
Loading…
Cancel
Save