Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct
- {
- int code;
- char nom[50];
- char type[20];
- float prix;
- struct article *suivant;
- struct article *suivantpanier;
- }article;
- int main()
- {
- FILE *fres, *fdat;
- fdat = fopen("articles.dat", "r");
- fres = fopen("facture.res", "w");
- int selection=0,cpt= 1, y, code,codeA,i,cpta=1;
- article *deb, *courant, *suivant, *intercale , *debpanier, *suivantpanier, *panier;
- deb = malloc(sizeof(article));
- debpanier = malloc(sizeof(article));
- panier=debpanier;
- courant = deb;
- fscanf(fdat, "%5d", &code);
- while(!feof(fdat))
- {
- courant->code = code;
- fscanf(fdat, "%s %4f %50[^\n]", &courant->type, &courant->prix, &courant->nom);
- suivant = malloc(sizeof(article));
- (*courant).suivant = suivant;
- cpt++;
- fscanf(fdat, "%5d", &code);
- courant = suivant;
- }
- cpt--;
- while(selection!=3)
- {
- printf("%d article(s) ont été chargés\n", cpt);
- printf("1. Visualiser les articles\n");
- printf("2. Ajouter un article a votre panier\n");
- printf("3. Arreter l'encodage\n");
- scanf("%d", &selection);
- if(selection == 1)
- {
- courant = deb;
- for(y = 1; y <= cpt; y++)
- {
- printf("%d %s %s %4.2f\n", courant->code, courant->nom, courant->type, courant->prix);
- courant = courant->suivant;
- }
- }
- if(selection == 2)
- {
- printf("Entrez le code barre de l'article\n");
- scanf("%5d",&codeA);
- courant=deb;
- i=cpt;
- for(y=1;y<=i;y++)
- {
- if (courant->code==codeA)
- {
- panier=courant;
- suivantpanier = malloc(sizeof(article));
- (*panier).suivantpanier = suivantpanier;
- i=1;
- cpta++;
- }
- else{
- courant=courant->suivant;
- }
- }
- }
- if(selection==3){
- courant=panier;
- for(y = 1; y <=cpta; y++)
- {
- printf("%d %s %s %4.2f\n", courant->code, courant->nom, courant->type, courant->prix);
- courant = courant->suivantpanier;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement