From 7fccb5f0796ffd9c9f25ae247ba86346e30349fa Mon Sep 17 00:00:00 2001 From: johnny Date: Tue, 10 Jan 2023 08:54:16 +0100 Subject: [PATCH] Ajout des fichiers partie 2 avec structures et chargement non fonctionnel --- J2sae.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ J2sae.h | 49 ++++++++++++++++++++++++++++++++ J2test.h | 0 3 files changed, 134 insertions(+) create mode 100755 J2sae.c create mode 100755 J2sae.h create mode 100755 J2test.h diff --git a/J2sae.c b/J2sae.c new file mode 100755 index 0000000..11c3404 --- /dev/null +++ b/J2sae.c @@ -0,0 +1,85 @@ +#include "J2sae.h" + +int chargementCandidats(Candidat *tCandidats[], 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); + return -1; + } + fscanf(flot, "%d", tMax); + tCand = (Candidat **)malloc(sizeof(Candidat *) * (*tMax)); + if(tCand == NULL) + { + printf("Erreur d'allocation mémoire tableau candidat\n"); + exit(1); + } + for(i = 0; i < *tMax; i++) + { + c = lireCandidat(flot); + tCand[i] = c; + } + tCandidats = tCand; +} + +Candidat * lireCandidat(FILE *flot) +{ + 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->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); + c->tchoix = (Choix **)malloc(sizeof(Choix *) * c->nombreChoix); + while(i <= c->nombreChoix) + { + c->tchoix[i] = lireChoix(flot); + i++; + } + return c; +} + +Choix * lireChoix(FILE *flot) +{ + 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->decisionResp, &c->decisionCand); + return c; +} + +void globale(void) +{ + Candidat **tCandidats, c; + int tMax; + chargementCandidats(tCandidats, &tMax); + afficherCandidat(*tCandidats[0]); +} + +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); +} \ No newline at end of file diff --git a/J2sae.h b/J2sae.h new file mode 100755 index 0000000..aa90d95 --- /dev/null +++ b/J2sae.h @@ -0,0 +1,49 @@ +#include +#include +#include +#include + +typedef struct +{ + char dept[31]; + int nbP; + char respAd[31]; +} Departement; + +typedef struct maillonDept +{ + Departement d; + struct maillonDept *suiv; + +} MaillonDept,*ListeDept; + +typedef struct +{ + char nom[31]; + ListeDept lDept; +} VilleIUT; + +typedef struct +{ + char ville[31]; + char dep[31]; + int decisionResp; + int decisionCand; +} Choix; + + +typedef struct +{ + int numeroC; + char nom[31]; + char prenom[31]; + float notes[4]; + int nombreChoix; + Choix **tchoix; +} Candidat; + +int chargementCandidats(Candidat *tCandidats[], int *tMax); +Candidat * lireCandidat(FILE *flot); +Choix * lireChoix(FILE *flot); +void afficherCandidat(Candidat c); +void globale(void); \ No newline at end of file diff --git a/J2test.h b/J2test.h new file mode 100755 index 0000000..e69de29