diff --git a/adherent.txt b/adherent.txt index 53e9f9d..beb6d11 100644 --- a/adherent.txt +++ b/adherent.txt @@ -1,7 +1,6 @@ -2 18 29 10 2022 1 -14 25 14 05 2007 1 -56 14 11 09 2001 0 -69 5 13 11 2015 1 -77 6 7 01 2015 0 -89 17 14 07 2016 1 - +2 18 29 10 2022 1 +14 25 14 5 2007 1 +23 10 17 7 1789 1 +56 5 13 11 2015 1 +69 6 7 1 2015 0 +77 17 14 7 2016 1 diff --git a/fonction.c b/fonction.c index 5c280ca..4a59222 100644 --- a/fonction.c +++ b/fonction.c @@ -78,6 +78,34 @@ int ajouter(int tab[], int nb, int val, int tphys) { return pos; } +int ajouterAdherent(int tabAdhe[], int tabPoints[], int jour[], int mois[], int annee[], int carte[], int nb, int tmax) { + int val, trouve, points = 10, valJour, valMois, valAnnee, perdue = 1, pos, coderetour; + printf("Nouveau numéro de carte : "); + scanf("%d",&val); + pos = recherche(tabAdhe, val, nb, &trouve); + coderetour = ajouter(tabAdhe, nb, val, tmax); + if (coderetour == -1) { + printf("Erreur ajout du nouvel élement !\n"); + return nb; + } + printf("\nJour : "); + scanf("%d",&valJour); + printf("\nMois : "); + scanf("%d",&valMois); + printf("\nAnnée : ",valAnnee); + scanf("%d",&valAnnee); + tabPoints[pos] = points; + jour[pos] = valJour; + mois[pos] = valMois; + annee[pos] = valAnnee; + carte[pos] = perdue; + nb += 1; + return nb; + + + +} + int suppression(int tab[], int tabPoints[], int nb, int val) { int pos, trouve; @@ -203,7 +231,7 @@ void alimenterCarte (int tabAdherent[], int tabPoint[],int nb) -int SauvegardeAdherent(int tabAdherent[], int tailleL) { +int SauvegardeAdherent(int tabAdherent[], int tabPoints[], int jour[], int mois[], int annee[], int carte[], int tailleL) { int i; FILE* flot = fopen("adherent.txt","w"); if (flot == NULL) { @@ -211,8 +239,9 @@ int SauvegardeAdherent(int tabAdherent[], int tailleL) { return -1; } for (i = 0 ; i < tailleL ; i++) { - fprintf(flot,"%d\n",tabAdherent[i]); + fprintf(flot,"%d %d %d %d %d %d\n",tabAdherent[i],tabPoints[i],jour[i],mois[i],annee[i],carte[i]); } + fclose(flot); return 0; } diff --git a/fonction.h b/fonction.h index 50970ac..85b7a48 100644 --- a/fonction.h +++ b/fonction.h @@ -13,6 +13,8 @@ void decalageGauche(int tabTri[], int nb, int pos); int ajouter(int tab[], int nb, int val, int tphys); +int ajouterAdherent(int tabAdhe[], int tabPoints[], int jour[], int mois[], int annee[], int carte[], int nb, int tmax); + int suppression(int tab[], int tabPoints[], int nb, int val); @@ -25,5 +27,4 @@ void affichageTous(int tabNumCarte[], int tabPoint[], int carte[], int jour[], i void affichageCarte(int tabAdhe[], int tabPoints[], int jour[], int mois[], int annee[], int carte[], int nb); - -int SauvegardeAdherent(int tabAdherent[], int tailleL); \ No newline at end of file +int SauvegardeAdherent(int tabAdherent[], int tabPoints[], int jour[], int mois[], int annee[], int carte[], int tailleL); \ No newline at end of file diff --git a/test.c b/test.c index bec2774..7f35cb6 100644 --- a/test.c +++ b/test.c @@ -4,34 +4,35 @@ int main(void) { int tabAdhe[50], tabPoints[50], jour[50], mois[50], annee[50], carte[50], tailleL; - // int codeSauv, coderetour=-1; + int codeSauv, coderetour=-1; tailleL=chargementAdherent(tabAdhe,tabPoints,jour,mois,annee,carte,50); - printf("%d\n",carte[3]); affichageCarte(tabAdhe,tabPoints,jour,mois,annee,carte,tailleL); affichageTous(tabAdhe,tabPoints,jour,mois,annee,carte,tailleL); + ajouterAdherent(tabAdhe,tabPoints,jour,mois,annee,carte,tailleL,50); + affichageCarte(tabAdhe,tabPoints,jour,mois,annee,carte,tailleL); // affichageInfo(tabAdhe,tabPoints,jour,mois,annee,carte,tailleL); // tailleL=ajouter(tab,tailleL,69,50); // affichageTest(tab,tailleL); // tailleL=suppression(tab,tailleL,69); // affichageTest(tab,tailleL); - // printf("Sauvegarder ? (1 : Oui, 2 : Non)\n"); - // scanf("%d",&codeSauv); - // if (codeSauv == 1) { + 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; + while(coderetour == -1) { + coderetour = SauvegardeAdherent(tabAdhe,tabPoints, jour, mois, annee, carte, 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