From dd46d261abc0bcdca6b448de07dbd62b0e9a70b4 Mon Sep 17 00:00:00 2001 From: Alix JEUDI--LEMOINE Date: Sat, 24 Dec 2022 01:18:21 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20des=20fonctions=20essentielles=20=C3=A0?= =?UTF-8?q?=20la=20partie=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/II/deux.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/II/deux.c diff --git a/src/II/deux.c b/src/II/deux.c new file mode 100644 index 0000000..af6e43c --- /dev/null +++ b/src/II/deux.c @@ -0,0 +1,77 @@ +/*! + \file deux.c + \author GOIGOUX Lucie & JEUDI--LEMOINE Alix + \date 23/12/22 + \brief Partie 2 de la SAE 1.02 + + Application de gestion des candidature dans les IUT de France +*/ + +#include +#include +#include +#include "deux.h" + + +Candidat* creerCandidat(void) { + return (Candidat*) malloc(sizeof(Candidat)); +} + +void afficherCandidat(Candidat* candidat) { + printf("Candidat '%s %s' :" + "\n - Moyenne en mathématiques : %f\n - Moyenne en français : %f" + "\n - Moyenne en anglais : %f\n - Moyenne en spécialité : %f\n\n", + candidat->prenom, candidat->nom, + candidat->moyenneMath, candidat->moyenneFrancais, + candidat->moyenneAnglais, candidat->moyenneSpecialite); +} + +ListeCandidats lireCandidats(int* nbCandidats) { + FILE *fe = fopen("donnees/candidats.don", "r"); + + if(fe == NULL) { + fprintf(stderr, "Erreur: impossible de lire le fichier candidats.don"); + return NULL; + } + + fscanf(fe, "%d", nbCandidats); + + ListeCandidats liste = (ListeCandidats) malloc(*nbCandidats*sizeof(Candidat)); + + for(int i=0; i<*nbCandidats; i++) { + Candidat* candidat = creerCandidat(); + fscanf(fe, "%*d\n%[^\n]\n%[^\n]\n%f\n%f\n%f\n%f\n%d", + candidat->nom, candidat->prenom, + &candidat->moyenneMath, &candidat->moyenneFrancais, + &candidat->moyenneAnglais, &candidat->moyenneSpecialite, + &candidat->nbCandidatures); + + ListeCandidatures listeCandidatures = (ListeCandidatures) malloc(candidat->nbCandidatures*sizeof(Candidature*)); + candidat->listeCandidatures = listeCandidatures; + + for(int j=0; jnbCandidatures; j++) { + Candidature* candidature = (Candidature*) malloc(sizeof(Candidature)); + fscanf(fe, "\n%[^\n]\n%[^\n]\n%d%d", + candidature->ville, candidature->departement, + &candidature->decision, &candidature->validation); + candidat->listeCandidatures[j] = candidature; + } + + liste[i] = candidat; + } + + return liste; +} + +int sauvegarderCandidats(ListeCandidats liste) { + return 0; +} + +void test2(void) { + int nbCandidats; + //printf("pa kc"); + ListeCandidats liste = lireCandidats(&nbCandidats); + + afficherCandidat(liste[0]); + afficherCandidat(liste[1]); +} \ No newline at end of file