Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define N 15
  5. int main(int argc, char argv[])
  6. {
  7. FILE *fp;
  8. int i=0,v[100],cont=0,cont1=0,found=0,x=0,j;
  9. char mm[100][16],mr[200][19],mn[100][19];
  10. if(argc!=3)
  11. {
  12. printf("ERRORE LINEA DI COMANDO\n\n");
  13. return -1;
  14. }
  15. fp=fopen("magazzino.txt","r");
  16. if(fp==(NULL))
  17. {
  18. printf("ERRORE SCANSIONE FILE MAGAZZINO\n\n");
  19. return -2;
  20. }
  21. else
  22. {
  23. while(fscanf(fp,"%s %d",mm[i],&v[i])!=EOF)
  24. {
  25. i++;
  26. cont1++;
  27. }
  28. }
  29. for(i=0;i<cont1;i++)
  30. {
  31. printf("%s %d\n\n",mm[i],v[i]);
  32. }
  33.  
  34. fclose(fp);
  35.  
  36.  
  37. fp=fopen("richieste.txt","r");
  38. if(fp==(NULL))
  39. {
  40. printf("ERRORE SCANSIONE FILE RICHIESTE\n\n");
  41. return -3;
  42. }
  43. i=0;
  44. cont=0;
  45. while(fscanf(fp,"%s",mr[i])!=EOF)
  46. {
  47. i++;
  48. cont++;
  49. }
  50.  
  51. printf("\n\n\n\n\nRichieste\n\n\n\n\n");
  52. for(i=0;i<cont;i++)
  53. {
  54. printf("%s\n\n",mr[i]);
  55. }
  56. fclose(fp);
  57.  
  58. for(i=0;i<cont1;i++)
  59. {
  60. for(j=0; j<cont; j++)
  61. {
  62. if(strcmp(mm[i],mr[j])==0)
  63. {
  64. v[i]=v[i]-1;
  65. found=1;
  66. }
  67. }
  68. if(found==0)
  69. {
  70. strcpy(mn[x],mm[i]);
  71. x++;
  72. }
  73. found=0;
  74. }
  75. for(i=0;i<cont1;i++)
  76. {
  77. if(v[i]<0)
  78. {
  79. printf("eccedenza %s di %d\n",mm[i],-v[i]);
  80. }
  81. }
  82.  
  83. for(i=0;i<x;i++)
  84. {
  85. printf("il prodotto %s non e' disponibile in negozio\n",mn[i]);
  86. }
  87.  
  88. return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement