Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. void add()
  2. {
  3.  
  4.  
  5. HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  6. int sign;
  7. char ch;
  8. f = fopen(name, "r+b");
  9. fread(&list, sizeof(struct product), n, f);
  10. int j = n;
  11. do
  12. {
  13. SetConsoleTextAttribute(hConsole, (WORD)((15 << 4) | 4));
  14. printf("Input type of product: 1- drink 2-chocolate: ");
  15. SetConsoleTextAttribute(hConsole, (WORD)((15 << 4) | 0));
  16. scanf("%d", &sign);
  17. if (sign == 1) list[j].tag = DRINK;
  18. else list[j].tag = CHOCOLATE;
  19. switch (list[j].tag)
  20. {
  21. case DRINK:
  22. { printf("name of drink: ");
  23. scanf("%s", list[j].name);
  24. printf("Enter calor of drink: ");
  25. scanf("%d", &list[j].calor);
  26. printf("Enter value of drink: ");
  27. scanf("%d", &list[j].value);
  28. printf("Enter strength of drink: ");
  29. scanf("%d", &list[j].drink.strength); break;
  30. }
  31. case CHOCOLATE:
  32. {
  33. printf("Enter name of chocolate:");
  34. scanf("%s", list[j].name);
  35. printf("Enter calor of chocolate: ");
  36. scanf("%d", &list[j].calor);
  37. printf("Enter value of chocolate: ");
  38. scanf("%d", &list[j].value);
  39. printf("Enter weigth of chocolate: ");
  40. scanf("%d", &list[j].chocolate.weigth);
  41. printf("Enter filling of chocolate: ");
  42. scanf("%s", list[j].chocolate.filling); break;
  43. }
  44. } //end of switch
  45. SetConsoleTextAttribute(hConsole, (WORD)((15 << 4) | 2));
  46. printf("Continue? [y/n] ");
  47. SetConsoleTextAttribute(hConsole, (WORD)((15 << 4) | 0));
  48. getchar();
  49. ch = getchar();
  50. j++;
  51. } while ((ch != 'n') && (ch != 'N'));
  52. fclose(f);
  53. n = j;
  54. f = fopen(name, "r+b");
  55. for (j = 0; j < n; j++)
  56. {
  57. fwrite(&list[j],sizeof(struct product),1,f);
  58. }
  59. fclose(f);
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement