You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
109 lines
2.7 KiB
109 lines
2.7 KiB
#include "J2sae.h"
|
|
|
|
Candidat ** chargementCandidats(int *tMax)
|
|
{
|
|
FILE *flot;
|
|
Candidat **tCand, *c;
|
|
int i;
|
|
flot = fopen("Candidats.don", "r");
|
|
if(flot == NULL)
|
|
{
|
|
printf("Erreur lors de l'ouverture du fichier candidat\n");
|
|
fclose(flot);
|
|
exit(1);
|
|
}
|
|
fscanf(flot, "%d", tMax);
|
|
printf("tMax : %d\n", *tMax);
|
|
tCand = (Candidat **)malloc(sizeof(Candidat *) * (*tMax));
|
|
printf("Allocation du tableau\n");
|
|
if(tCand == NULL)
|
|
{
|
|
printf("Erreur d'allocation mémoire tableau candidat\n");
|
|
fclose(flot);
|
|
exit(1);
|
|
}
|
|
printf("Début du chargement\n");
|
|
for(i = 0; i < *tMax; i++)
|
|
{
|
|
c = lireCandidat(flot);
|
|
tCand[i] = c;
|
|
}
|
|
printf("Fin du chargement\n");
|
|
fclose(flot);
|
|
return tCand;
|
|
}
|
|
|
|
Candidat * lireCandidat(FILE *flot)
|
|
{
|
|
printf("Lecture d'un candidat\n");
|
|
Candidat *c;
|
|
Choix choix;
|
|
int i = 0;
|
|
c = (Candidat *)malloc(sizeof(Candidat));
|
|
if(c == NULL)
|
|
{
|
|
printf("Erreur d'allocation mémoire candidat\n");
|
|
exit(1);
|
|
}
|
|
fscanf(flot, "%d%*c", &c->numeroC);
|
|
fgets(c->nom, 31, flot);
|
|
c->nom[strlen(c->nom) - 1] = '\0';
|
|
fgets(c->prenom, 31, flot);
|
|
c->prenom[strlen(c->prenom) - 1] = '\0';
|
|
fscanf(flot, "%f%f%f%f%*c", &c->notes[0], &c->notes[1], &c->notes[2], &c->notes[3]);
|
|
fscanf(flot, "%d%*c", &c->nombreChoix);
|
|
c->tchoix = (Choix **)malloc(sizeof(Choix *) * c->nombreChoix);
|
|
afficherCandidat(c);
|
|
printf("Nombre de choix : %d\n", c->nombreChoix);
|
|
while(i < c->nombreChoix)
|
|
{
|
|
c->tchoix[i] = lireChoix(flot);
|
|
i = i + 1;
|
|
}
|
|
return c;
|
|
}
|
|
|
|
Choix * lireChoix(FILE *flot)
|
|
{
|
|
printf("Lecture d'un choix\n");
|
|
Choix *c;
|
|
c = (Choix *)malloc(sizeof(Choix));
|
|
if(c == NULL)
|
|
{
|
|
printf("Erreur d'allocation mémoire choix\n");
|
|
exit(1);
|
|
}
|
|
fgets(c->ville, 31, flot);
|
|
c->ville[strlen(c->ville) - 1] = '\0';
|
|
fgets(c->dep, 31, flot);
|
|
c->dep[strlen(c->dep) - 1] = '\0';
|
|
fscanf(flot, "%d%d%*c", &c->decisionResp, &c->decisionCand);
|
|
afficherChoix(c);
|
|
return c;
|
|
}
|
|
|
|
void globale(void)
|
|
{
|
|
Candidat **tCandidats, c;
|
|
int tMax, i, j;
|
|
tCandidats = chargementCandidats(&tMax);
|
|
for(i = 0; i < tMax; i++)
|
|
{
|
|
afficherCandidat(tCandidats[i]);
|
|
for(j = 0; j < tCandidats[i]->nombreChoix; j++)
|
|
{
|
|
afficherChoix(tCandidats[i]->tchoix[j]);
|
|
}
|
|
}
|
|
}
|
|
|
|
void afficherChoix(Choix *c)
|
|
{
|
|
printf("%s\t%s\t%d\t%d\n", c->ville, c->dep, c->decisionResp, c->decisionCand);
|
|
}
|
|
|
|
void afficherCandidat(Candidat *c)
|
|
{
|
|
printf("Afficher candidat\n");
|
|
printf("%d\t%s\t%s\t%.2f\t%.2f\t%.2f\t%.2f\n", c->numeroC, c->nom, c->prenom, c->notes[0], c->notes[1], c->notes[2], c->notes[3]);
|
|
} |