diff --git a/FICHIERCYRIAQUE/ajoutClient.c b/FICHIERCYRIAQUE/ajoutClient.c index 6743700..3672d9e 100644 --- a/FICHIERCYRIAQUE/ajoutClient.c +++ b/FICHIERCYRIAQUE/ajoutClient.c @@ -1,6 +1,50 @@ #include "sae.h" +int modifclientglobal (void) +{ + char choix; + int n,coderreur; + + printf("Bienvenue dans l'application de modulation client .\nque souhaitez vous faire aujourd'hui ?\n"); + + while(choix!='X') + { + n=compteurtaillelogique(); + printf("Appuyez sur 'A' pour ajouter un client,\nsur 'S' pour changer l'état de suspension d'une carte client,\nsur 'D' pour supprimer un client ,\nsur 'V' pour afficher le dossier client,\nOu sur 'X' pour sortir du programme !\n"); + scanf("%c%*c",&choix); + while (choix!='A' && choix!='S' && choix!='D' && choix!='X' && choix!='V') + { + printf("Entrée incorrect, veuillez ressasisir.\n"); + scanf("%c%*c",&choix); + } + if (choix=='A') + { + coderreur=ajoutClient(); + } + + if (choix=='S') + { + coderreur=suspensioncarte(&n); + } + + if (choix=='D') + { + coderreur=supressionclient(&n); + } + + if (choix=='V') + { + coderreur=affichage(); + } + + } + + printf("au revoir !\n"); + return 0; + +} + int ajoutClient (void) { @@ -9,7 +53,7 @@ int ajoutClient (void) FILE *fichierclient; printf("ajout d'un client au programme de fidélité...\nquel est le numéro de ce client ?\n"); - scanf("%d",&numeroclient); + scanf("%d%*c",&numeroclient); while (numeroclient<0) { printf("le numéro du client ne peut être négatif , réessayez\n"); @@ -39,7 +83,7 @@ int ajoutClient (void) fscanf(fichierclient,"%d%f%d",&verif,&cagnotte,&suspension); } - fclose(fichierclient); + fclose (fichierclient); fichierclient=fopen("fichierclient.don","a"); if (fichierclient==NULL) { @@ -47,28 +91,25 @@ int ajoutClient (void) return -2; } - fprintf(fichierclient,"%d\t%*.2f\t%d\n",numeroclient,100,0); + fprintf(fichierclient,"%d\t%.2f\t%d\n",numeroclient,0.00,0); fclose(fichierclient); printf("client ajouté au programme de fidélité ! \n"); return numeroclient; } - -int supensioncarte (void) + +int suspensioncarte (int *n) { - int tabNC [100]={0}; - float tabCAG [100]={0}; - int tabSUS [100]={0}; + int tabNC [100]; + float tabCAG [100]; + int tabsuspension [100]; - int nc,nouvellecarte,sus,compteur=0,compteurCAG,taillemax=100,recherche,n; + int nc,nouvellecarte,suspension,compteur=0,compteurCAG,taillemax=100,recherche; float cagnotte; FILE *fichierClientmegacool; - n=compteurtaillelogique(); - - fichierClientmegacool=fopen("fichierclient.don","r"); if (fichierClientmegacool==NULL) { @@ -76,94 +117,113 @@ int supensioncarte (void) return -2; } - fscanf(fichierClientmegacool,"%d%f%d",&nc,&cagnotte,&sus); - while(feof(fichierClientmegacool)==0) + fscanf(fichierClientmegacool,"%d%f%d",&nc,&cagnotte,&suspension); + while (feof(fichierClientmegacool)==0) { tabNC[compteur]=nc; tabCAG[compteur]=cagnotte; - tabSUS[compteur]=sus; + tabsuspension[compteur]=suspension; compteur=compteur+1; - if (compteur>n) + if (compteur>*n) { printf("erreur de taille\n"); return 0; } - fscanf(fichierClientmegacool,"%d%f%d",&nc,&cagnotte,&sus); + fscanf(fichierClientmegacool,"%d%f%d",&nc,&cagnotte,&suspension); } - fclose(fichierClientmegacool); + fclose (fichierClientmegacool); printf("quel carte souhaitez vous suspendre ou désuspendre (entrez numéro client)\n"); - scanf("%d",&recherche); - while(recherche<0) + scanf("%d%*c",&recherche); + while (recherche<0) { printf("numéro non valide , veuillez réessayez\n"); scanf("%d",&recherche); } - for (compteur=0;compteurtaillemax) - { - printf("le client n'existe pas\n"); - return -2; - } } - if (tabSUS[compteurCAG]==1) + if (suspension!=0 && suspension!=1) { - printf("création d'une nouvelle carte pour le client %d\n",tabNC[compteurCAG]); - - printf("numéro de la nouvelle carte ?\n"); - scanf("%d",&nouvellecarte); + printf("le numéro client n'existe pas\n"); + return -7; + } - for (compteur=0;compteur*n) + { + printf("erreur de taille\n"); + return 0; + } + fscanf(fichierClientmegacool,"%d%f%d",&nc,&cagnotte,&suspension); + } + fclose(fichierClientmegacool); + + for (compteur=0;compteur<*n;compteur++) + if (tabNC[compteur]==recherche2) + { + while (compteur<=*n) + { + tabNC[compteur]=tabNC[compteur+1]; + tabCAG[compteur]=tabCAG[compteur+1]; + tabsuspension[compteur]=tabsuspension[compteur+1]; + compteur=compteur+1; + nt=0; + + } + + *n=*n-1; + } + + if (nt!=0) + { + printf("le numéro client n'existe pas\n"); + return -6; + } + + fichierClientmegacool=fopen("fichierclient.don","w"); + if (fichierClientmegacool==NULL) + { + printf("Probléme d'ouverture"); + return -2; + } + + for (compteur=0;compteur<*n;compteur++) + + fprintf(fichierClientmegacool, "%d\t%.2f\t%d\n",tabNC[compteur],tabCAG[compteur],tabsuspension[compteur]); + + fclose(fichierClientmegacool); + + printf("client supprimé.\n"); + + return 0; + +} + +int affichage (void) +{ + int compteur,nc,suspension; + float cagnotte; + + FILE *flot; + flot=fopen("fichierclient.don","r"); + if (flot==NULL) + { + printf("erreur d'ouverture du fichier\n"); + return -1; + } + fscanf(flot,"%d%f%d",&nc,&cagnotte,&suspension); + while (feof(flot)==0) + { + printf("%d\t%.2f\t%d\n",nc,cagnotte,suspension); + fscanf(flot,"%d%f%d",&nc,&cagnotte,&suspension); + } + return 0; +} int compteurtaillelogique (void) @@ -215,6 +373,4 @@ int compteurtaillelogique (void) fclose(flot); return i; -} - -//fix les probléme de négativités \ No newline at end of file +} \ No newline at end of file diff --git a/FICHIERCYRIAQUE/fichierclient.don b/FICHIERCYRIAQUE/fichierclient.don index d3ebc5d..11bb2be 100644 --- a/FICHIERCYRIAQUE/fichierclient.don +++ b/FICHIERCYRIAQUE/fichierclient.don @@ -1,2 +1,2 @@ -12 10.00 0 - +14 0.00 0 +18 0.00 0 diff --git a/FICHIERCYRIAQUE/sae b/FICHIERCYRIAQUE/sae index 1fd5d3a..593e1ac 100755 Binary files a/FICHIERCYRIAQUE/sae and b/FICHIERCYRIAQUE/sae differ diff --git a/FICHIERCYRIAQUE/sae.h b/FICHIERCYRIAQUE/sae.h index 595024f..4f223a3 100644 --- a/FICHIERCYRIAQUE/sae.h +++ b/FICHIERCYRIAQUE/sae.h @@ -1,5 +1,8 @@ #include +int modifclientglobal (void); int ajoutClient (void); -int supensioncarte (void); -int compteurtaillelogique (void); \ No newline at end of file +int suspensioncarte (int *n); +int compteurtaillelogique (void); +int supressionclient (int *n); +int affichage (void); diff --git a/FICHIERCYRIAQUE/testsae.c b/FICHIERCYRIAQUE/testsae.c index c1914c4..6be52ae 100644 --- a/FICHIERCYRIAQUE/testsae.c +++ b/FICHIERCYRIAQUE/testsae.c @@ -2,7 +2,6 @@ int main(void) { - ajoutClient(); - supensioncarte(); + modifclientglobal(); return 0; //cette instruction sert a dire au sys que prog termine }