Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. //lab 11.2, 11.3 -> 11 decembrie 2019
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. struct shopItem
  6. {
  7. char *name;
  8. int amount;
  9. } items[100], citems[100];
  10.  
  11. int main()
  12. {
  13. items[0].name = "ciocolata";
  14. items[0].amount = 100;
  15. items[1].name = "capsuni";
  16. items[1].amount = 200;
  17. items[2].name = "haribo";
  18. items[2].amount = 40;
  19.  
  20. FILE *f;
  21. f = fopen("date.txt", "r+");
  22. if (f==NULL)
  23. printf("asdad");
  24. for(int i=0; i<3; i++)
  25. fprintf(f, "%s %d\n", items[i].name, items[i].amount);
  26.  
  27. rewind(f);
  28. for(int i=0; i<3; i++)
  29. {
  30. citems[i].name = (char*)malloc(100);
  31. fscanf(f, "%s", citems[i].name), fscanf(f, "%d", &citems[i].amount);
  32. }
  33. //fprintf("%d", fclose(f));
  34. int a = fclose(f);
  35. printf("%d", a);
  36.  
  37. FILE *g;
  38. g = fopen("datesort.txt", "r+");
  39. if(g==NULL)
  40. printf("Asdasda");
  41. for(int i=0; i<3; i++)
  42. fprintf(g, "%s %d\n", citems[i].name, citems[i].amount);
  43.  
  44. fclose(g);
  45. return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement