From 9d94955eab7aaf12f7d8343e553fa57bab25707e Mon Sep 17 00:00:00 2001 From: lolaborie Date: Sat, 5 Nov 2022 16:58:38 +0100 Subject: [PATCH] =?UTF-8?q?05/11=20Fonction=20de=20sauvegarde=20ajout?= =?UTF-8?q?=C3=A9e=20pour=20les=20adh=C3=A9rents=20(=C3=A0=20modifier=20av?= =?UTF-8?q?ec=20toutes=20les=20futures=20informations=20disponibles)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adherent.txt | 5 +++-- fonction.c | 17 +++++++++++++---- fonction.h | 5 ++++- test.c | 25 ++++++++++++++++++++++--- 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/adherent.txt b/adherent.txt index 3c11a7e..391a9ee 100644 --- a/adherent.txt +++ b/adherent.txt @@ -1,5 +1,6 @@ 2 -89 14 -77 56 +69 +77 +89 diff --git a/fonction.c b/fonction.c index 60bcd4c..6ce2b90 100644 --- a/fonction.c +++ b/fonction.c @@ -166,7 +166,7 @@ void alimenterCarte (int tabAdherent[], int tabPoint[],int nb) i = recherche(tabAdherent, num, nb, &trouve); if (trouve == 1) { - printf("Qu'elle formule :\n"); + printf("Quelle formule :\n"); printf("A : 5€ -> 5 points\n"); printf("B : 10€ -> 12 point\n"); printf("C : 15€ -> 20 point\n"); @@ -204,9 +204,18 @@ void alimenterCarte (int tabAdherent[], int tabPoint[],int nb) - - - +int SauvegardeAdherent(int tabAdherent[], int tailleL) { + int i; + FILE* flot = fopen("adherent.txt","w"); + if (flot == NULL) { + printf("Erreur d'ouverture du fichier !\n"); + return -1; + } + for (i = 0 ; i < tailleL ; i++) { + fprintf(flot,"%d\n",tabAdherent[i]); + } + return 0; +} diff --git a/fonction.h b/fonction.h index 3274aa4..af377c5 100644 --- a/fonction.h +++ b/fonction.h @@ -24,4 +24,7 @@ void affichageInfo(int tabNumCarte[], int tabPoint[], int carte[], int jour[], i void affichageTous(int tabNumCarte[], int tabPoint[], int carte[], int jour[], int mois[], int annee[],int taille); -void affichageTest(int tabAdhe[], int nb); \ No newline at end of file +void affichageTest(int tabAdhe[], int nb); + + +int SauvegardeAdherent(int tabAdherent[], int tailleL); \ No newline at end of file diff --git a/test.c b/test.c index e6a1d25..8ccf711 100644 --- a/test.c +++ b/test.c @@ -3,12 +3,31 @@ int main(void) { - int tab[50], tailleL; + int tab[50], tailleL, codeSauv, coderetour=-1; tailleL=chargementAdherent(tab,50); affichageTest(tab,tailleL); tailleL=ajouter(tab,tailleL,69,50); affichageTest(tab,tailleL); - tailleL=suppression(tab,tailleL,69); - affichageTest(tab,tailleL); + // tailleL=suppression(tab,tailleL,69); + // affichageTest(tab,tailleL); + printf("Sauvegarder ? (1 : Oui, 2 : Non)\n"); + scanf("%d",&codeSauv); + if (codeSauv == 1) { + + while(coderetour == -1) { + coderetour = SauvegardeAdherent(tab,tailleL); + if (coderetour == 0) { + printf("Sauvegarde réussie !\n"); + break; + } + else { + printf("Sauvegarde échouée\n"); + printf("Réessayer ?(1 : Oui, 2 : Non\n"); + scanf("%d",&codeSauv); + if (codeSauv == 2) break; + + } + } + } return 0; } \ No newline at end of file