From 0629490ce2588457b2ccfa90eb933e5e98cfd626 Mon Sep 17 00:00:00 2001 From: DahmaneYanis Date: Thu, 5 Jan 2023 12:04:51 +0100 Subject: [PATCH] Chargement du fichier Log --- source/sae.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/source/sae.c b/source/sae.c index 0efc8c0..36beac0 100644 --- a/source/sae.c +++ b/source/sae.c @@ -1,5 +1,11 @@ #include "../header/sae.h" +/* +================================================ + Partie 1 +================================================ +*/ + /** * @brief Fonction globale qui : * - Charge les fichiers dans les structures adaptées @@ -8,14 +14,69 @@ */ void Globale(void) { + Log * tLog; + //Chargement des fichiers + tLog = chargementLog("../donnees/log.don"); //Appel du menu visiteur - menuVisiteur(); + //menuVisiteur(); //Sauvegarde dans les fichiers } +/** + * @brief Charge un fichier de logs dans un tableau de structures Log + * @param nomFichier [CHAINE DE CARACTERE] Le nom du fichier à charger + * @return Log* [TABLEAU DYNAMIQUE DE STRUCTURE] Le tableau de structures Log contenant les logs du fichier + */ +Log * chargementLog(char * nomFichier) +{ + FILE * fichier; + Log * tLog; + Log * tAnnexe; + + int nbLogMax; + int nbLog; + int i; + + fichier = fopen(nomFichier, "r"); + + if (fichier == NULL) + { + printf("Erreur de fichier\n"); + exit(1); + } + + tLog = (Log *) malloc(sizeof(Log)*5); + nbLogMax = 5; + + i = 0; + while (!feof(fichier)) + { + // Taille physique insuffisante + if (i == nbLogMax) + { + tAnnexe = realloc(tLog, sizeof(Log)*(nbLogMax + 5)); + + // Test si le realloc n'a pas fonctionné + if (tAnnexe == NULL) + { + printf("Problème de realloc\n"); + exit(1); + } + + tLog = tAnnexe; + nbLogMax+= 5; + } + + fscanf(fichier, "%s %s", tLog[i].utilisateur, tLog[i].mdp); + i++; + } + + return tLog; +} + /** * @brief Cette fonction affiche le menu des options disponibles pour un visiteur * et demande à l'utilisateur de faire son choix en appelant la fonction @@ -137,7 +198,6 @@ void seConnecterTest(void) saisieMdp(mdp); // Récupération du mot de passe } - /** * @brief Affichage de la bannière de connexion. */