Hi,
I have some problem concerning files. I have a first one (PRODUIT.DAT) containing this.
Code:
11 MEMOREXCD 29.99 20.75 100
15 CARTOUCHENOIR 27.99 22.25 150
18 CARTOUCHECOULEUR 49.99 38.50 20
24 SOURISSANSFIL 49.99 32.55 10
28 CLAVIER 29.99 15.00 15
11, 15, 18, 24 and 28 are the number of the product (iNoProduit). After, there is the name of the product(sNomProduit). then there is the selling value (fPrixProduit), the orriginal cost of the product (fCoutProduit) and finally, the quantity of the product (iQtdProduit). After, I have a second file (TRANSAC.DAT)
Code:
1 10 10
1 12 5
3 13 15
1 14 6
1 16 1
2 18 2
First, where there is 1 1 3 1 1 2 (iNoTransaction), this mean 1 = add product quantity, 2 = remove product quantity and 3 = delete the entire product. 10 12 13 14 16 18 mean the number of the product on which you want to make the modification (related to the previous file (iNoProduit)). As you can see, 10 is not in PRODUIT.DAT which mean that the program create a file named MESSAGE.DAT in which he put the number in it and tell that he is not in the list. Finally, 10 5 15 6 1 2 (iQtdTransaction) mean the quantity you want to change (add or remove) depending if iNoTransaction = 1 or 2.
At the end, the program generate a file called RESULTAT.DAT in which he put the number of the product, the name of the product, it's price, it's original cost and it's new quantity.
Code:
11 MEMOREXCD 29.99 20.75 100
15 CARTOUCHENOIR 27.99 22.25 150
18 CARTOUCHECOULEUR 49.99 38.50 18
(hope this was a bit clear)
here's the part I did
Code:
#include <stdio.h>
#include <myconio.h>
#include <string.h>
int main()
{
FILE * pFichier;
FILE * pFichierTransac;
FILE * pFichierMessage;
FILE * pFichierResultat;
char ligne [BUFSIZ];
char ligneTransac [BUFSIZ];
char sNomProduit;
int iNoProduit;
int iNoProduitTransac;
int iQtdProduit;
int iNoTransaction;
float fPrixProduit;
float fCoutProduit;
int iQtdTransaction;
pFichierMessage = fopen ("MESSAGE.DAT" , "w");
pFichierResultat= fopen ("RESULTAT.DAT" , "w");
pFichier = fopen ("PRODUITS.DAT" , "r"); //ouverture du fichier
if (pFichier == NULL) perror ("Erreur a l'ouverture du fichier");
else {
while (fgets (ligne , BUFSIZ, pFichier) != NULL)
{
sscanf (ligne, "%d %s %f %f %d",iNoProduit,&sNomProduit,fPrixProduit,
fCoutProduit,iQtdProduit);
pFichierTransac = fopen ("TRANSAC.DAT" , "r");
if (pFichierTransac == NULL) perror ("Erreur a l'ouverture du fichier");
else {
while (fgets (ligneTransac , BUFSIZ, pFichierTransac) != NULL)
sscanf (ligne, "%d %d %d",iNoTransaction,iNoProduitTransac,
iQtdTransaction);
if (iNoProduitTransac == iNoProduit){
switch ( iNoTransaction ) {
case 1: iQtdProduit = iQtdProduit + iQtdTransaction;
case 2: iQtdProduit = iQtdProduit - iQtdTransaction;
}
}else{
fprintf(pFichierMessage,"Produit %d non trouve --> transaction IGNOREE", iNoTransaction);
}
fprintf(pFichierResultat,"%d %s %f %f %i", iNoProduit,sNomProduit,fPrixProduit,fCoutProduit,iQtdProduit);
}
}
}
getch();
}
First, this program crash. Also, I don't know how to simply remove one entire product (if iNoTransaction = 3). Finally, since there is surely a lot of mistake in this code, don't hesitate to tell me.
Thanks a lot