Advertisement
Guest User

Untitled

a guest
Nov 18th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. #include<windows.h>
  5. #define MAX 100
  6.  
  7.  
  8. struct shop
  9. {
  10.  
  11. char name [30];
  12. int price;
  13. int count;
  14.  
  15. } shop_list[MAX];
  16.  
  17. void init_list(void);
  18. void enter(void);
  19. int delet(void);
  20. void list(void);
  21. int menu_select(void);
  22. int find_free(void);
  23.  
  24. int main(void)
  25.  
  26.  
  27. {
  28.  
  29.  
  30. char choice;
  31. init_list();
  32. for(;;)
  33. {
  34. system("cls");
  35. choice = menu_select();
  36. switch(choice)
  37. {
  38. case 1: enter();
  39. system("pause>0");
  40. break;
  41. case 2: delet();
  42. system("pause>0");
  43. break;
  44. case 3: list();
  45. system("pause>0");
  46. break;
  47. case 4: exit(0);
  48. }
  49.  
  50. }
  51. return 0;
  52. }
  53. void init_list(void)
  54. {
  55. register int t;
  56. for (t=0; t<MAX; ++t) shop_list[t].name[0] = '\0';
  57. }
  58.  
  59.  
  60.  
  61. int menu_select(void)
  62. {
  63. char s[80];
  64. int c;
  65.  
  66. printf("1. Enter name\n");
  67. printf("2. Delete name\n");
  68. printf("3. Display the list\n");
  69. printf("4. Exit\n");
  70.  
  71. do
  72. {
  73. printf("\nEnter the number of the desired item: ");
  74. gets(s);
  75. c = atoi(s);
  76. } while ((c<0 || c>4));
  77. return c;
  78.  
  79. }
  80.  
  81. void enter (void)
  82. {
  83. char name[80];
  84. int price;
  85. int count;
  86.  
  87. printf("Enter name:");
  88. gets(name);
  89.  
  90. for(int i=0;shop_list[i].name[0] && i < MAX;i++)
  91. {
  92. if(strcmp(shop_list[i].name,name) == 0)
  93. {
  94. printf("Product exists\n");
  95. printf("Enter just count:");
  96. scanf("%i",&count);
  97. shop_list[i].count = shop_list[i].count + count;
  98. return;
  99. }
  100. }
  101.  
  102.  
  103. printf("Enter price:");
  104. scanf("%i",&price);
  105. printf("Enter count:");
  106. scanf("%i",&count);
  107.  
  108. register int i = 0;
  109.  
  110.  
  111.  
  112.  
  113.  
  114. int slot;
  115. slot = find_free();
  116. if(slot==-1)
  117. {
  118. printf("\nList is full ");
  119. return;
  120.  
  121. }
  122. else
  123. {
  124. strcpy(shop_list[slot].name,name);
  125. shop_list[slot].price = price;
  126. shop_list[slot].count = count;
  127.  
  128. }
  129. }
  130.  
  131.  
  132. int find_free(void)
  133. {
  134. register int t;
  135. for (t=0; shop_list[t].name[0] !='\0' && t<MAX; ++t);
  136. if (t==MAX) return -1;
  137. return t;
  138. }
  139. int delet(void)
  140. {
  141. char s[80];
  142. printf("Enter name of product for del:");
  143. gets(s);
  144. register int i = 0;
  145. int flag = -1;
  146. for(i=0;shop_list[i].name[0] && i < MAX;i++)
  147. {
  148. if(strcmp(shop_list[i].name,s) == 0)
  149. {
  150. flag = 0;
  151. shop_list[i].name[0] = '\0';
  152. }
  153. }
  154. return flag;
  155.  
  156. }
  157. void list(void)
  158. {
  159. register int t;
  160. for(t=0; t<MAX; ++t)
  161.  
  162.  
  163. {
  164. if(shop_list[t].name[0])
  165. {
  166.  
  167.  
  168.  
  169. printf("%s ", shop_list[t].name);
  170. printf("%i ", shop_list[t].price);
  171. printf("%i\n", shop_list[t].count);
  172.  
  173. }
  174.  
  175.  
  176. }
  177. printf("\n\n");
  178. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement