Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4. /*
  5. // Strucure de type article
  6. typedef struct{
  7. char libelle[19];
  8. int codeArticle, codeR;
  9. float prixU;
  10. struct article *suivant;
  11. }article;
  12. */
  13. // Structure de type rayon
  14. typedef struct{
  15. char nom[11];
  16. int codeRayon;
  17. struct rayon *rsuivant;
  18. }rayon;
  19.  
  20. main(){
  21. /*Déclarations des fichiers*/
  22. FILE *fdat, *fdat2, *fres;
  23. fdat2 = fopen("produit.dat","r");
  24. fdat = fopen("rayon.dat","r");
  25. fres = fopen("ticket.res","w");
  26.  
  27. /* Déclarations des données*/
  28. int cpt=1, i, choixRayon=0,n=1,quant,choixArt;
  29. // article *deb, *courant, *suivant;
  30. rayon *rdeb, *rcourant, *rsuivant;
  31. rdeb = malloc(sizeof(rayon));
  32. rcourant = rdeb;
  33.  
  34. /*Lecture des rayons dans le premier fichier*/
  35. fscanf(fdat,"%d",&rcourant->codeRayon);
  36. while(!feof(fdat))
  37. {
  38. fscanf(fdat,"%10s",&rcourant->nom);
  39. rsuivant = malloc(sizeof(rayon));
  40. rcourant->rsuivant = rsuivant;
  41. cpt++;
  42. rcourant = rsuivant;
  43. fscanf(fdat,"%d",&rcourant->codeRayon);
  44. }
  45. cpt-=1;
  46.  
  47. rcourant=rdeb;
  48. for(i=1;i<=cpt;i++)
  49. {
  50. rcourant=rcourant->rsuivant;
  51. }
  52. (*rcourant).rsuivant = NULL;
  53.  
  54. //Lecture des articles dans le second fichier
  55. deb = malloc(sizeof(article));
  56. courant = deb;
  57. fscanf(fdat2,"",&courant->codeR);
  58. while(!feof(fdat2)){
  59. fscanf(fdat,"%5d%18s%4f",&courant->codeArticle, &courant->libelle, &courant->prixU);
  60. suivant = malloc(sizeof(article));
  61. courant->suivant = suivant;
  62. n++;
  63. courant = suivant;
  64. }
  65. n-=1;
  66. /*
  67. courant=deb;
  68. for(i=1;i<=cpt;i++)
  69. {
  70. courant=courant->suivant;
  71. }
  72. courant->suivant = NULL;
  73. */
  74. /*Interarction console*/
  75. printf("Votre magasin Colruyt vous souhaite la bienvenue !\n");
  76. printf("Commencez vos achats en choisissant un rayon !\n");
  77. rcourant=rdeb;
  78. for(i=1;i<=cpt;i++)
  79. {
  80. printf("%d : %10s\n",rcourant->codeRayon,rcourant->nom);
  81. rcourant=rcourant->rsuivant;
  82. }
  83. printf("Tapez le numero du rayon : \n");
  84. scanf("%d",&choixRayon);
  85.  
  86. courant = deb;
  87. for(i=1;i<n;i++){
  88. if(courant->codeR == choixRayon){
  89. printf("%18s ",courant->libelle);
  90. }
  91. }
  92. printf("Tapez le numero de l'article : \n");
  93. scanf("%d", &choixArt);
  94. printf("En quelle quantité?\n");
  95. scanf("%d", &quant);
  96.  
  97. fprintf(fres,"Colruyt\n");
  98. fprintf(fres,"+-------+------------------------+----------+--------+--------+---------+\n");
  99. fprintf(fres,"| N° art| Dénomination | Vidanges | Quant. | Prix U | Montant |\n");
  100. fprintf(fres,"+-------+------------------------+----------+--------+--------+---------+\n");
  101.  
  102. for(i=1;i<cpt;i++){
  103. fprintf(fres,"| | | | | | |");
  104. }
  105. fprintf(fres,"+-------+------------------------+----------+--------+--------+---------+\n");
  106.  
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement