bonjour ,g commencer a faire un programme me permetant d'enregistrer des client dans un fichier a l'inde d'une fonction et de les consulte en utilisant une autre fonction, cela semblait fonctionner jusqu'au momment ou g creer une fonction execmenu affin de rendre le programme + intuitif
le probleme est que depuis que j'utilise la fonction execmenu, je n'arrive plus a consulter les enregistrement se trouvant dans le fichier
pourriez vous me dire ce qui ne vas pas dans mon code? merci
Gemini
// le code
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
/* definition des structure ------------------------------------*/
struct cli
{
int id_cli;
char nom[25];
float som_due;
int reduc;
int tva;
};
struct fact
{
int id_fact;
char nom_cli[25];
float mont_tot;
};
/* déclaration des fonctions --------------------------------*/
int execmenu();
void encodecli(struct cli *t);
void encodefact(struct fact *t_fact);
void affiche (struct cli t);
/* Fonction principale -----------------------------------------*/
void main()
{
/*Déclarations ----------------------------------------------*/
struct cli tab[10];
struct fact tab_fact[10];
int choi;
/* Traitement -----------------------------------------------*/
do
{
choi=execmenu();
switch (choi)
{
case 1: encodecli(tab);
break;
case 2: encodefact(tab_fact);
break;
case 3: affiche (*tab);
break;
case 4: printf("choix 4");
break;
case 5: printf("choix 5");
break;
case 99: printf("choix 99");
break;
}
}
while (choi!=99);
}
/* fonction execmenu ----------------------------------------*/
int execmenu()
{
int choix;
clrscr();
printf("\n\n\n\n\n\n\n\n");
printf(" ******************************************\n");
printf(" * <1> Ajouter un client *\n");
printf(" * <2> Ajouter une facture *\n");
printf(" * <3> Consulter la liste des clients *\n");
printf(" * <4> Consulter la liste des factures *\n");
printf(" * <5> Lister les mauvais payeur *\n");
printf(" * <99> quitter *\n");
printf(" * Votre choix : *\n");
printf(" ******************************************\n");
do
{
scanf("%d",&choix);
}
while (choix!=1 && choix!=2 && choix!=3 && choix!=4 && choix!=5 && choix!=99);
return choix;
}
/*fonction d'encodage des client ----------------------------*/
void encodecli(struct cli *t)
{
FILE *ptr;
int ok;
char choix;
ptr=fopen("acces.dat","a+b");
if(ptr!=NULL)
{
choix='o';
while(choix == 'o')
{
clrscr();
printf("\nentrer le nom :");
scanf("%s",t->nom);
printf("entrer le taux de la tva, 25 ou 12:");
scanf("%d",&t->tva);
t->id_cli+1;
fflush(stdin);
fwrite(t,sizeof(*(t)),1,ptr);
do
{
ok=0;
printf("Nouvelle fiche (o/n) ?");
choix = getchar();
choix=tolower(choix);
if(choix!='o' && choix!='n')
{
printf("\nRépondez \"o\" ou \"n\" \n");
ok=1;
}
}while(ok == 1);
}// fin while ok
}// fin if ptr NULL
fclose(ptr);
}
/*fonction d'encodage des client ----------------------------*/
void encodefact(struct fact *t_fact)
{
int rep_fact;
int art=0;
int prix=0;
int quant=0;
int total=0;
int temp=0;
int somme=0;
do
{
clrscr();
printf("entrer le numero de l'article:");
scanf("%d", &art);
printf("entrer le prix de l'article:");
scanf("%d", &prix);
printf("entrer le nombre d'aricle:");
scanf("%d", &quant);
somme = prix*quant;
total += somme;
printf("voulez vous continuer? 1 pour oui, 2 pour non");
scanf("%d",&rep_fact);
}
while(rep_fact==1);
if (total > 1200)
temp = total-(total/100*3);
else
if(total > 500)
temp = total - total/100;
printf("le montant de la facture est de %d",temp);
}
//Affichage du contenu du fichier principal
void affiche(struct cli t)
{
FILE *ptr;
ptr=fopen("acces.dat","r");
fread(&t,sizeof(t),1,ptr);
while(fread(&t,sizeof(struct cli),1,ptr) != 0)//(!feof(ptr))
{
printf("\nNom : %s, tva : %d",t.nom,t.tva);
}
fclose(ptr);
}