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
| #include <stdio.h>
#include <stdlib.h>
int Codecltn, Codeclt, CodePdt, CodePdtn, nbv, k;
float Qte;
int find, trouve;
char date[30];
FILE* produit;
FILE* client;
FILE* vente;
void verif_existp() {
int m, find = 0;
client = fopen("produit.doc", "r+" );
printf("donner un code produit n°%d :", k);
scanf("%d", &CodePdtn);
while (find == 0) {
m = ftell(produit);
fscanf(produit, "%d", &CodePdt);
if (CodePdt == CodePdtn) {
printf("donner la quantité du produit vendu n°:%d", k);
scanf("%f", & Qte);
printf("donner la date de la vente n°:%d ", k);
scanf("%s", date);
find = 1;
fseek(produit, m, SEEK_SET);
scanf("%d", &CodePdt);
fprintf(vente, "Cclt:%d Cpdt:%d Qpdt:%f date:%s", Codecltn, CodePdtn, Qte, date);
}
else {
printf("le code client n'existe pas" );
find = 0;
}
fclose(produit);
}
}
void verif_existc() {
int m, n, trouve = 0;
client = fopen("client.doc", "r+" );
printf("donner un code client n°%d :", k);
scanf("%d", &Codecltn);
while (trouve == 0) {
n = ftell(client);
fscanf(client, "%d", &Codeclt);
if (Codeclt == Codecltn) {
verif_existp();
trouve = 1;
fseek(client, n, SEEK_SET);
}
else {
printf("le code client n'existe pas" );
trouve=0;
}
fclose(client);
}
}
int main(int argc, char *argv[]) {
printf("donner le nombre de ventes:" );
scanf("%d", &nbv);
vente = fopen("vente.doc", "w" );
for (k = 1; k <= nbv; k++) {
verif_existc();
fclose(vente);
}
system("PAUSE" );
return 0;
} |