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