From ec68914001712ca2823b2646e3be348aa4a80d4e Mon Sep 17 00:00:00 2001 From: Roxane ROSSETTO Date: Tue, 8 Nov 2022 18:22:20 +0100 Subject: [PATCH] =?UTF-8?q?Modification=20du=20fichier=20commun.c,=20ajout?= =?UTF-8?q?=20des=20fonctions=20comptage=20activit=C3=A9s=20et=20affichage?= =?UTF-8?q?=201=20client,=20affichage=20tous=20les=20clients,=20affichage?= =?UTF-8?q?=20compteur=20d'activit=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- commun.c | 214 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 214 insertions(+) create mode 100644 commun.c diff --git a/commun.c b/commun.c new file mode 100644 index 0000000..ac6b131 --- /dev/null +++ b/commun.c @@ -0,0 +1,214 @@ +//main commun +#include "hCommun.h" + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//LOLA + +int Fillvar(int *tAd, char tnom[][15], char tpnom[][15], int *tage, int *tstate, int *tacti, int *tpasseoupas, int *tptsbought, int *tptsbonus, char *tcateg, int tmax)//lis le fichier et met les valeurs dans les tableaux +{ + FILE *f; + f = fopen("donneeClient.don", "r"); + if (f == NULL) + { + printf("Problème d'ouverture du fichier Clients..."); + return -1; + } + int i = 0; + int numAd, age, state, acti, passeoupas, ptsbought, ptsbonus; + char categ, fnom[15], fprenom[15]; + + fscanf(f, "%6d", &numAd); + fscanf(f, "%s", fnom); + fscanf(f, "%s", fprenom); + fscanf(f, "%2d", &age); + fscanf(f, "%d", &state); + fscanf(f, "%d", &acti); + fscanf(f, "%d", &passeoupas); + fscanf(f, "%2d", &ptsbought); + fscanf(f, "%2d%*c", &ptsbonus); + fscanf(f, "%c", &categ); + + while (!feof(f)) + { + if (i == tmax) + { + printf("Problème de gestion: trop de clients enregistrés à ce jour"); + return -1; + } + + + tAd[i] = numAd; + strcpy(tnom[i], fnom); + strcpy(tpnom[i], fprenom); + tage[i] = age; + tstate[i] = state; + tacti[i] = acti; + tpasseoupas[i] = passeoupas; + tptsbought[i] = ptsbought; + tptsbonus[i] = ptsbonus; + tcateg[i] = categ; + + i++; + + fscanf(f, "%6d", &numAd); + fscanf(f, "%s", fnom); + fscanf(f, "%s", fprenom); + fscanf(f, "%2d", &age); + fscanf(f, "%d", &state); + fscanf(f, "%d", &acti); + fscanf(f, "%d", &passeoupas); + fscanf(f, "%2d", &ptsbought); + fscanf(f, "%2d%*c", &ptsbonus); + fscanf(f, "%c", &categ); + + } + fclose(f); + return 0; +} + + + + + + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//ROXANE + + + +//Fonction recherche, (*coderet = 1 si trouvé, = 0 si pas trouvé.) (*rang = rang a laquel se trouve ou doit se trouver la valeur) +void fRecherche(int *tAd, int n, int noClient, int *coderet, int *rang) +{ + int i; + + for(i = 0; i < n; i++) + { + if(tAd[i] == noClient) + { + *coderet = 1; + *rang = i; + return; + } + if(tAd[i] > noClient) + + *rang = i; + return; + } +} + + +//Affichage D'UN client avec toutes ses données. +void fAffichage1Client(int *tAd, char tnom[][15], char tpnom[][15], int *tage, int *tstate, int n, int noClient ) +{ + int i, coderet, rang, trouve, NonTrouve; + + + fRecherche(tAd, n, noClient, &coderet, &rang); + + trouve = coderet; + + while (trouve == 0) + { + if(coderet == 0) + { + printf("Le numero client n'a pas été trouvé \n"); + printf("Veuillez entrer a nouveau le N° Client ou taper -1 pour annuler\n"); + scanf("%d", &NonTrouve); + } + if(NonTrouve==-1) + return; + else + fRecherche(tAd, n, noClient, &coderet, &rang); + trouve=coderet; + } + printf(" N° Client\t Nom\t Prénom\t Age\t Tarif\n"); + printf("%d\t %s \t %S\t %d\t %S\n", tAd[rang], tnom[rang], tpnom[rang], tage[rang], tstate[rang]); + +} + + +//Affichage plusieurs client avec toutes les données +int afficheTous(int *tAd, char tnom[][15], char tpnom[][15], int *tage, int *tstate, int n, int noClient ) +{ + int i; + printf(" N° Client\t Nom\t Prénom\t Age\t Tarif\n"); + for (int i = 0; i < n; ++i) + { + printf("%d\t %s\t %s\t %d\t %s\n", tAd, tnom, tpnom, tage, tstate); + } + return i; +} + +// calcul du nombre d'entree par jour et l'affiche +int affNbmEntree( int *tpasseoupas, int tlog) +{ + int i, nbentre; + for( i=0 ; i