Advertisement
Guest User

Untitled

a guest
Dec 16th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.46 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. typedef struct
  6. {
  7.     int code;
  8.     char nom[50];
  9.     char type[20];
  10.     float prix;
  11.     struct article *suivant;
  12.     struct article *suivantpanier;
  13. }article;
  14.  
  15. int main()
  16. {
  17.         FILE *fres, *fdat;
  18.  
  19.         fdat = fopen("articles.dat", "r");
  20.         fres = fopen("facture.res", "w");
  21.  
  22.         int selection=0,cpt= 1, y, code,codeA,i,cpta=1;
  23.  
  24.         article *deb, *courant, *suivant, *intercale , *debpanier, *suivantpanier, *panier;
  25.         deb = malloc(sizeof(article));
  26.         debpanier = malloc(sizeof(article));
  27.         panier=debpanier;
  28.         courant = deb;
  29.         fscanf(fdat, "%5d", &code);
  30.         while(!feof(fdat))
  31.         {
  32.             courant->code = code;
  33.             fscanf(fdat, "%s %4f %50[^\n]", &courant->type, &courant->prix, &courant->nom);
  34.             suivant = malloc(sizeof(article));
  35.             (*courant).suivant = suivant;
  36.             cpt++;
  37.             fscanf(fdat, "%5d", &code);
  38.             courant = suivant;
  39.         }
  40.  
  41.         cpt--;
  42.     while(selection!=3)
  43.     {
  44.         printf("%d article(s) ont été chargés\n", cpt);
  45.         printf("1. Visualiser les articles\n");
  46.         printf("2. Ajouter un article a votre panier\n");
  47.         printf("3. Arreter l'encodage\n");
  48.         scanf("%d", &selection);
  49.  
  50.         if(selection == 1)
  51.         {
  52.             courant = deb;
  53.             for(y = 1; y <= cpt; y++)
  54.             {
  55.                 printf("%d %s %s %4.2f\n", courant->code, courant->nom, courant->type, courant->prix);
  56.                 courant = courant->suivant;
  57.             }
  58.         }
  59.         if(selection == 2)
  60.         {
  61.           printf("Entrez le code barre de l'article\n");
  62.           scanf("%5d",&codeA);
  63.           courant=deb;
  64.           i=cpt;
  65.           for(y=1;y<=i;y++)
  66.           {
  67.             if (courant->code==codeA)
  68.             {
  69.               panier=courant;
  70.               suivantpanier = malloc(sizeof(article));
  71.               (*panier).suivantpanier = suivantpanier;
  72.               i=1;
  73.               cpta++;
  74.             }
  75.             else{
  76.               courant=courant->suivant;
  77.             }
  78.           }
  79.         }
  80.         if(selection==3){
  81.         courant=panier;
  82.             for(y = 1; y <=cpta; y++)
  83.             {
  84.                 printf("%d %s %s %4.2f\n", courant->code, courant->nom, courant->type, courant->prix);
  85.                 courant = courant->suivantpanier;
  86.             }
  87.         }
  88.        
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement