Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. /*
  2. CONTENU : Séance 3 - Gestion de stocks
  3. AUTEUR :
  4. CREATION : 21/11/2018
  5. MODIFICATION : 14/11/2019
  6. */
  7.  
  8. // librairies
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <stdbool.h>
  12.  
  13. // Structures
  14.  
  15. // Constantes
  16. #define NBR_PRODUITS 100
  17.  
  18. // Variables
  19.  
  20. // Types
  21. typedef struct {
  22. int reference;
  23. int x;
  24. char fabricant[40];
  25. char modele[40];
  26. int quantite;
  27. float prix;
  28. } fiche_produits;
  29.  
  30. // Prototypes
  31. int LireFichierProduit(char[],fiche_produits); // A MODIFIER : mettre le bon type
  32.  
  33. // corps du programme principal
  34. int main(int argc, char *argv[])
  35. {
  36. int reference;
  37. FILE*ft;
  38. ft=fopen("produits.csv", "a");
  39. fiche_produits mes_produits; // A MODIFIER : mettre le bon type
  40. int nombre_produits=0; // nombre de produits du revendeur
  41.  
  42. // Lecture du fichier des stocks
  43. if ((nombre_produits=LireFichierProduit(argv[1],mes_produits))==-1) return -1;
  44.  
  45. // Menu principal
  46. int choix=0;
  47. do {
  48. printf("Veuillez saisir votre choix\n");
  49. printf("1 - Afficher un produit\n");
  50. printf("2 - Ajouter un produit\n");
  51. printf("3 - Supprimer un produit\n");
  52. printf("4 - Montant du stock\n");
  53. printf("5 - Quitter l'application\n");
  54. printf("Votre choix : ");
  55. scanf("%d",&choix);
  56. switch (choix) {
  57. case 1:
  58. printf("Quelle est la référence à rechercher ?"); scanf("%d", reference);
  59. break;
  60. case 2:
  61. break;
  62. case 3:
  63. break;
  64. case 4:
  65. default:
  66. break;
  67. }
  68. } while (choix!=5);
  69. fclose (ft);
  70.  
  71.  
  72. return 0;
  73. }
  74.  
  75. // Rôle : Lecture du fichier des stocks
  76. int LireFichierProduit(char fichier[], fiche_produits mes_produits) {
  77.  
  78. FILE *FichierProduit;
  79. int nombre_produits=0;
  80.  
  81. int reference;
  82. char fabricant[40];
  83. char modele[40];
  84. int quantite;
  85. float prix;
  86.  
  87. if ((FichierProduit=fopen("produits.csv","r"))==NULL) {
  88. printf("Impossible d'accèder au fichier\n");
  89. nombre_produits=-1;
  90. } else {
  91. while(fscanf(FichierProduit,"%d %s %s %d %f",&reference,fabricant,modele,&quantite,&prix)==5) {
  92. nombre_produits++;
  93. printf("produit %d %s %s %d %f\n",reference,fabricant,modele,quantite,prix);
  94. /* mes_produits.reference=reference;
  95. mes_produits.fabricant=fabricant;
  96. mes_produits.modele=modele;
  97. mes_produits.quantite=quantite;
  98. mes_produits.prix=prix;
  99. */
  100. }
  101. }
  102. fclose(FichierProduit);
  103.  
  104. return nombre_produits;
  105. }
  106.  
  107. void EcrireFicierProduit(mes_produits.reference, mes_produits.quantite, mes_produits.prix, mes_produits.modele, mes_produits.fabricant){
  108. /*
  109. printf("Tapez la référence de votre produit\n"); scanf("%d", &mes_produits.reference);
  110. printf("Tapez la quantité de votre produit\n"); scanf("%d", &mes_produits.quantite);
  111. printf("Tapez le prix de votre produit\n"); scanf("%f", &mes_produits.prix);
  112. printf("Vous avez ajouté :\n Référence : %d\n Fabricant : %s\n Modèle : %s\n Quantité : %d\n Prix : %f\n", mes_produits.reference, mes_produits.fabricant, mes_produits.modele, mes_produits.quantite, mes_produits.prix);
  113. fprintf(ft,"\n%d %s %s %d %f", mes_produits.reference, mes_produits.fabricant, mes_produits.modele, mes_produits.quantite, mes_produits.prix);
  114. */
  115. }
  116.  
  117. void TrouverProduits()
  118. // printf("Tapez le fabricant de votre produit\n"); scanf("%s", &mes_produits.fabricant);
  119. // printf("Tapez le modèle de votre produit\n"); scanf("%s", &mes_produits.modele);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement