diff --git a/J2sae.c b/J2sae.c index 11c3404..c50301e 100755 --- a/J2sae.c +++ b/J2sae.c @@ -1,6 +1,6 @@ #include "J2sae.h" -int chargementCandidats(Candidat *tCandidats[], int *tMax) +Candidat ** chargementCandidats(int *tMax) { FILE *flot; Candidat **tCand, *c; @@ -10,25 +10,32 @@ int chargementCandidats(Candidat *tCandidats[], int *tMax) { printf("Erreur lors de l'ouverture du fichier candidat\n"); fclose(flot); - return -1; + 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; } - tCandidats = tCand; + 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; @@ -38,24 +45,27 @@ Candidat * lireCandidat(FILE *flot) printf("Erreur d'allocation mémoire candidat\n"); exit(1); } - fscanf(flot, "%d", &c->numeroC); + 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->notes[0], &c->notes[1], &c->notes[2], &c->notes[3]); - fscanf(flot, "%d", &c->nombreChoix); + 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); - while(i <= c->nombreChoix) + afficherCandidat(c); + printf("Nombre de choix : %d\n", c->nombreChoix); + while(i < c->nombreChoix) { c->tchoix[i] = lireChoix(flot); - i++; + 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) @@ -67,19 +77,33 @@ Choix * lireChoix(FILE *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->decisionResp, &c->decisionCand); + fscanf(flot, "%d%d%*c", &c->decisionResp, &c->decisionCand); + afficherChoix(c); return c; } void globale(void) { Candidat **tCandidats, c; - int tMax; - chargementCandidats(tCandidats, &tMax); - afficherCandidat(*tCandidats[0]); + 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) +void afficherCandidat(Candidat *c) { - printf("%d\t%s\t%s\t%.2f\t%.2f\t%.2f\t%.2f\t%d\n", c.numeroC, c.nom, c.prenom, c.notes[0], c.notes[1], c.notes[2], c.notes[3], c.nombreChoix); + 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]); } \ No newline at end of file diff --git a/J2sae.h b/J2sae.h index aa90d95..2df3f5f 100755 --- a/J2sae.h +++ b/J2sae.h @@ -5,22 +5,22 @@ typedef struct { - char dept[31]; - int nbP; - char respAd[31]; + char dept[31]; + int nbP; + char respAd[31]; } Departement; typedef struct maillonDept { - Departement d; - struct maillonDept *suiv; + Departement d; + struct maillonDept *suiv; } MaillonDept,*ListeDept; typedef struct { - char nom[31]; - ListeDept lDept; + char nom[31]; + ListeDept lDept; } VilleIUT; typedef struct @@ -42,8 +42,9 @@ typedef struct Choix **tchoix; } Candidat; -int chargementCandidats(Candidat *tCandidats[], int *tMax); +Candidat ** chargementCandidats(int *tMax); Candidat * lireCandidat(FILE *flot); Choix * lireChoix(FILE *flot); -void afficherCandidat(Candidat c); +void afficherCandidat(Candidat *c); +void afficherChoix(Choix *c); void globale(void); \ No newline at end of file diff --git a/J2test.c b/J2test.c new file mode 100755 index 0000000..7df8c6a --- /dev/null +++ b/J2test.c @@ -0,0 +1,7 @@ +#include "J2sae.h" + +int main(void) +{ + globale(); + return 0; +} \ No newline at end of file