From 9575c11d50d9a5cb9beb56ffbff6bb9bf99c28b9 Mon Sep 17 00:00:00 2001 From: Kyllian Chabanon Date: Fri, 30 Dec 2022 22:52:56 +0100 Subject: [PATCH] =?UTF-8?q?Am=C3=A9lioration=20de=20la=20fonction=20de=20c?= =?UTF-8?q?hargement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...nformationsIUT.don => informationsIUT.txt} | 0 Partie_1/partie1.c | 72 +++++++++---------- Partie_1/partie1.h | 10 +-- Partie_1/structures.c | 21 ++++++ Partie_1/structures.h | 20 ++++++ Partie_1/test.c | 5 +- SAE.h | 32 +++------ 7 files changed, 92 insertions(+), 68 deletions(-) rename Partie_1/{informationsIUT.don => informationsIUT.txt} (100%) create mode 100644 Partie_1/structures.c create mode 100644 Partie_1/structures.h diff --git a/Partie_1/informationsIUT.don b/Partie_1/informationsIUT.txt similarity index 100% rename from Partie_1/informationsIUT.don rename to Partie_1/informationsIUT.txt diff --git a/Partie_1/partie1.c b/Partie_1/partie1.c index 2a1c44a..a7b1ac7 100755 --- a/Partie_1/partie1.c +++ b/Partie_1/partie1.c @@ -1,68 +1,66 @@ #include "partie1.h" - -ListeDept listenouv(void) -{ - return NULL; -} - -ListeDept insererEnTete(ListeDept l, char departement[], int nbP) -{ - MaillonDept *m; - m = (MaillonDept *)malloc(sizeof(MaillonDept)); - if (m == NULL) - { - printf("Fonction insererEnTete : problème malloc"); - exit(1); - } - strcpy(m->departement, departement); - m->nbP = nbP; - m->suiv = l; - return l; -} - +/* ListeDept chargeListeDept(VilleIUT *tiut[]) { int i = 0; ListeDept liste = listenouv(); - FILE *file = fopen("informationsIUT.don", "r"); + FILE *file = fopen("informationsIUT.txt", "r"); while (!feof(file)) { - } -} +}*/ -int chargementVilleIUT(VilleIUT *tiut[]) +int chargementVillesIUT(VilleIUT *tiut[]) { - FILE *file = fopen("informationsIUT.don", "r"); - VilleIUT villeiut; + FILE *file = fopen("informationsIUT.txt", "r"); char ville[30], dept[30], nomResp[30]; - int nbP, i = 0; + int nbP, i = 0, trouve; if (file == NULL) { - printf("Fonction chargementVilleIUT : Problème lors de l'ouverture du fichier informations.don"); + printf("Fonction chargementVillesIUT : Problème lors de l'ouverture du fichier informationsIUT.txt"); exit(-1); } + while (!feof(file)) { - tiut[i] = (VilleIUT *)malloc(sizeof(VilleIUT)); - if (tiut[i] == NULL) + fscanf(file, "%s%s%d", ville, dept, &nbP); + fgets(nomResp, 30, file); + trouve = recherche(tiut, i, ville); + if (trouve == 0) { - printf("erreur malloc"); - exit(-1); + tiut[i] = (VilleIUT *)malloc(sizeof(VilleIUT)); + if (tiut[i] == NULL) + { + printf("Fonction chargementVillesIUT : Problème lors du malloc"); + exit(-1); + } + + strcpy(tiut[i]->ville, ville); + i++; } - fscanf(file, "%s%s%d", tiut[i]->ville, dept, &nbP); - fgets(nomResp, 30, file); - i++; } + fclose(file); return i; } +int recherche(VilleIUT *tiut[], int nb, char val[]) +{ + for (int i = 0; i < nb; i++) + { + if (strcmp(tiut[i]->ville, val) == 0) + { + return 1; + } + } + return 0; +} + void affichage(VilleIUT *tiut[], int nb) { for (int i = 0; i < nb; i++) { printf("%s\n", tiut[i]->ville); } -} \ No newline at end of file +} diff --git a/Partie_1/partie1.h b/Partie_1/partie1.h index bd4920b..fc932c7 100755 --- a/Partie_1/partie1.h +++ b/Partie_1/partie1.h @@ -1,13 +1,9 @@ #include #include -#include "../structures/structures.h" #include - +#include "structures.h" /* Fichier */ -int chargementVilleIUT(VilleIUT *tiut[]); +int chargementVillesIUT(VilleIUT *tiut[]); void affichage(VilleIUT *tiut[], int nb); - -/* File */ - -ListeDept listenouv(void); +int recherche(VilleIUT *tiut[], int nb, char val[]); \ No newline at end of file diff --git a/Partie_1/structures.c b/Partie_1/structures.c new file mode 100644 index 0000000..1278007 --- /dev/null +++ b/Partie_1/structures.c @@ -0,0 +1,21 @@ +#include "partie1.h" + +ListeDept listenouv(void) +{ + return NULL; +} + +ListeDept insererEnTete(ListeDept l, char departement[], int nbP) +{ + MaillonDept *m; + m = (MaillonDept *)malloc(sizeof(MaillonDept)); + if (m == NULL) + { + printf("Fonction insererEnTete : problème malloc"); + exit(1); + } + strcpy(m->departement, departement); + m->nbP = nbP; + m->suiv = l; + return l; +} \ No newline at end of file diff --git a/Partie_1/structures.h b/Partie_1/structures.h new file mode 100644 index 0000000..b14b5d4 --- /dev/null +++ b/Partie_1/structures.h @@ -0,0 +1,20 @@ +#include +#include +#include + +typedef struct maillonDept +{ + char departement[30]; + int nbP; + char resp[30]; + struct maillonDept *suiv; +} MaillonDept, *ListeDept; + +typedef struct +{ + char ville[30]; + ListeDept ldept; +} VilleIUT; + +ListeDept listenouv(void); +ListeDept insererEnTete(ListeDept l, char departement[], int nbP); \ No newline at end of file diff --git a/Partie_1/test.c b/Partie_1/test.c index a818674..bcca1b9 100755 --- a/Partie_1/test.c +++ b/Partie_1/test.c @@ -2,8 +2,9 @@ int main(void) { + int nbVilles; VilleIUT *tiut[100]; - int nb = chargementVilleIUT(tiut); - affichage(tiut, nb); + nbVilles = chargementVillesIUT(tiut); + affichage(tiut, nbVilles); return 0; } diff --git a/SAE.h b/SAE.h index da525b6..3211f99 100755 --- a/SAE.h +++ b/SAE.h @@ -3,21 +3,6 @@ #include #include -/* Partie 1 -typedef struct maillonDept -{ - char departement[30]; - int nbP; - char resp[30]; - struct maillonDept *suiv; -} MaillonDept, *ListeDept; - -typedef struct -{ - char ville[30]; - ListeDept ldept; -} VilleIUT; */ - /* Menus */ void choixMenu(void); void menuUtilisateur(void); @@ -27,20 +12,23 @@ void menuAdministrateur(void); /* V2 */ -typedef struct { +typedef struct +{ char departement[30]; int decisionAdmission; int decisionCandidat; } Departement; -typedef struct maillonDepartement { +typedef struct maillonDepartement +{ Departement v; struct maillonDepartement *suiv; } MaillonDepartement, *ListeDepartement; -typedef struct { +typedef struct +{ int num; - char nom[22]; // 20 caractere + 1 espace + 1 caractere de fin de chaine + char nom[22]; // 20 caractere + 1 espace + 1 caractere de fin de chaine char prenom[22]; // 20 caractere + 1 espace + 1 caractere de fin de chaine int tabMatiere[4]; int nbChoix; @@ -48,7 +36,8 @@ typedef struct { ListeDepartement ldept; } Admission; -typedef struct maillonAdmission { +typedef struct maillonAdmission +{ Admission v; struct maillonAdmission *suiv; } MaillonAdmission, *ListeAdmission; @@ -67,7 +56,6 @@ ListeAdmission MoyenneCandidats(ListeAdmission listeCandidats); int modifNoteMinAdmis(); int modifNbAdmisMax(); - /* V1 typedef struct { int num; @@ -95,7 +83,7 @@ typedef struct { int decisionAdmission5; int decisionCandidat5; } Admission; -// Utilisation d'une file car on a pas besoins de modifier les candidats, les mettre au milieu de la file, +// Utilisation d'une file car on a pas besoins de modifier les candidats, les mettre au milieu de la file, // on a juste besoin de les ajouter et de les supprimer, on cherche à les parcourir dans l'ordre d'arrivée // Pour mettre d'un coté les candidats traités et de l'autre les candidats non traités typedef struct maillonAdmission {