parent
473c980e16
commit
7fccb5f079
@ -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);
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
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);
|
Loading…
Reference in new issue