1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| #include <stdio.h>
#include <conio.h>
#include <string.h>
void ajout_data(struct gamme_audi*);
struct gamme_audi
{
short CE; //flag d'effacement (1(non effacé) ou 0(effacé))
char nref[21]; //référence de la designation
char marque[30]; //soit audi,merco,bmw
char model[30]; //indiquera la marque (merco, bm,audi)
float phtva; //prix tva non comprise
float tva; //le taux applicable au prix
float ptvac; //prix tva comprise
};
void main()
{
struct gamme_audi *data;
ajout_data(&data);
getch();
}
void ajout_data(struct gamme_audi *data)
{
int sw;
char rep;
FILE *f;
f=fopen("gamme_audi.dat","rb"); //ouverture en ajout
if(f==NULL)
{
printf("erreur");
}
else
{
sw=0;
while(sw==0)
{
//je ne presente pas le caractère d'effacement c pas prévu pour ici
fflush(stdin);
printf("\n n° de reference : ");
scanf("%s",(*data).nref); //ou bien &data->nref
fflush(stdin);
printf("\n marque du model : ");
scanf("%s",(*data).marque);
fflush(stdin);
printf("\n model : ");
scanf("%s",(*data).model);
fflush(stdin);
printf("\n prix hors tva : ");
scanf("%f",&(*data).phtva);
fflush(stdin);
printf("\n taux de tva : ");
scanf("%f",&(*data).tva);
fflush(stdin);
//calcul du prix tvac
(*data).ptvac=(*data).phtva*(*data).tva;
printf("\nle prix est calculer automatiquement : %.2f",data->ptvac);
fwrite(&data,sizeof(data),1,f); //ecriture dans le fichier
do
{
printf("\n\nvoulez vous ajouté un autre enregistrement ? (o/n) : ");
scanf("%c",&rep);
if(rep=='o' || rep=='O')
{
sw=0;
}
else
{
if(rep=='n'||rep=='N')
{
sw=1;
}
}
}
while(rep!='O' && rep!='o' && rep!='n' && rep!='N');
}
}
} |
Partager