From 31e701871c3082a54b7480f8787ac9163373f2fb Mon Sep 17 00:00:00 2001 From: DahmaneYanis Date: Sun, 6 Nov 2022 17:29:48 +0100 Subject: [PATCH] =?UTF-8?q?Trouver=20adh=C3=A9rent=20cr=C3=A9er=20et=20com?= =?UTF-8?q?ment=C3=A9=20|=20AfficheInfosAdh=C3=A9rent=20adapt=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- header/adherent.h | 2 ++ source/adherent.c | 45 +++++++++++++++++++++++++++++++-------------- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/header/adherent.h b/header/adherent.h index 741e25b..3b5e4d6 100644 --- a/header/adherent.h +++ b/header/adherent.h @@ -7,3 +7,5 @@ void AfficheAdherents(int tabNoCarte[], int tabEtatCarte[], int tabPointCarte[], void ligne(void); int AfficheInfosAdherent(int noCarte, int tabNoCarte[], int tabEtatCarte[], int tabPointCarte[], int nbAdherents); + +int TrouverAdherent(int tabNoCarte[], int nbAdherents, int noCarte, int *trouve); diff --git a/source/adherent.c b/source/adherent.c index 0e2682a..da321ef 100644 --- a/source/adherent.c +++ b/source/adherent.c @@ -234,27 +234,17 @@ void ligne(void) * @param tabEtatCarte [TABLEAU] Liste des états des cartes des adherents * @param tabPointCarte [TABLEAU] Liste des crédits pour chaque adhérent * @param nbAdherents [Taille Logique] Nombre d'adherents total - * @return int [CODE ERR] 0 -> Tout s'est bien passé | 1 -> Numéro de carte introuvable + * @return int [CODE ERR] 0 -> Tout s'est bien passé | -1 -> Numéro de carte introuvable */ int AfficheInfosAdherent(int noCarte, int tabNoCarte[], int tabEtatCarte[], int tabPointCarte[], int nbAdherents) { - int indice = 0, trouve = 0; - - // Vérifier l'existance du numéro de carte et si existe récupération de son indice - for (int i = 0; i < nbAdherents; i++) - { - if (tabNoCarte[i] == noCarte) - { - indice = i; - trouve = 1; - } - } + int trouve = 0, indice = TrouverAdherent(tabNoCarte, nbAdherents, noCarte, &trouve); // Vérifier l'éxistance de l'adherent // Affichage clean // Traitement du résultat de la recherche - if (!trouve) + if (!trouve && indice != -1) { printf("Adherent %d introuvable.\n", noCarte); @@ -269,4 +259,31 @@ int AfficheInfosAdherent(int noCarte, int tabNoCarte[], int tabEtatCarte[], int return 0; } -} \ No newline at end of file +} + +/** + * @brief Permet de déterminer si un adhérent existe et si oui de récupérer son indice + * + * @param tabNoCarte [TABLEAU] Liste des adhérents + * @param nbAdherents [Taille Logique] Nombre d'adhérents + * @param noCarte Numéro d'adhérent que l'on cherche + * @param trouve [POINTEUR] Vaut par défaut 0. Prend la valeur 1 si l'adhérent est trouvé + * @return int -1 -> Adhérent introuvable | Autre -> Indice de l'adherent + */ +int TrouverAdherent(int tabNoCarte[], int nbAdherents, int noCarte, int *trouve) +{ + int indice = 0, trouve = 0; + + // Vérifier l'existance du numéro de carte et si existe récupération de son indice + for (int i = 0; i < nbAdherents; i++) + { + if (tabNoCarte[i] == noCarte) + { + return i; + *trouve = 1; + } + } + + return -1; +} +