jaOjaa

ANOTHER FUCKING STACK

Mar 18th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4. #include <malloc.h>
  5. #include <string.h>
  6.  
  7. void clrscr() {
  8. system("@cls||clear");
  9. }
  10.  
  11. struct node {
  12. struct node *next;
  13. char name[30];
  14. int qty;
  15. char type[5];
  16. int price;
  17. };
  18.  
  19. struct node *start = NULL;
  20. struct node *create_ll(struct node*);
  21. struct node *display(struct node*);
  22. struct node *insert_end(struct node*);
  23. struct node *delete_beg(struct node*);
  24.  
  25. void menu() {
  26. printf("COOL COMPUTER ADMINSTRATOR\n");
  27. printf("++++++++++++++++++++++++++\n\n");
  28. printf("1. Item List\n");
  29. printf("2. Add <push> new item\n");
  30. printf("3. Delete <pop> recently added item\n");
  31. printf("4. Exit\n\n");
  32. printf("> Input your choice : ");
  33. }
  34.  
  35. int main() {
  36. int choice;
  37.  
  38. do {
  39. clrscr();
  40. menu();
  41. scanf("%d", &choice);
  42. switch(choice) {
  43. case 1: {
  44. clrscr();
  45. start = display(start);
  46. getch();
  47. break;
  48. }
  49. case 2: {
  50. clrscr();
  51. start = create_ll(start);
  52. printf("\n--- Item was sucessfully added! ---");
  53. getch();
  54. break;
  55. }
  56. case 3: {
  57.  
  58. break;
  59. }
  60. }
  61. } while (choice != 4);
  62. }
  63.  
  64. struct node *create_ll(struct node *start) {
  65. struct node *new_node, *ptr;
  66. char nname[20], ttype[20];
  67. int qqty, pprice;
  68. int tc = 0;
  69.  
  70. do {
  71. printf("> Input name [3...20] :");
  72. fflush(stdin);
  73. scanf("%[^\n]", &nname);
  74. } while (strlen(nname) < 3 || strlen(nname) > 20);
  75. do {
  76. printf("\n> Input type [processor/graphic card/memory] : ");
  77. scanf("%s", &ttype);
  78. if (strcmp("processor", ttype) == 0) {
  79. tc = 1;
  80. } else if (strcmp("graphic card", ttype) == 0) {
  81. tc = 1;
  82. } else if (strcmp("memory", ttype) == 0) {
  83. tc = 1;
  84. } else {
  85. tc = 0;
  86. }
  87. } while (tc == 0);
  88. do {
  89. printf("\n> Input quantity [1...20] : ");
  90. scanf("%d", &qqty);
  91. } while (qqty < 4 || qqty > 20);
  92. do {
  93. printf("\n > Input price [$1...$1000]: ");
  94. scanf("%d", &pprice);
  95. } while (pprice < 1 || pprice > 1000);
  96. new_node = (struct node* ) malloc(sizeof(struct node));
  97. strcpy(new_node -> name, nname);
  98. new_node -> qty = qqty;
  99. strcpy(new_node -> type, ttype);
  100. new_node -> price = pprice;
  101. if (start == NULL) {
  102. new_node -> next = NULL;
  103. start = new_node;
  104. } else {
  105. ptr = start;
  106. while (ptr -> next != NULL) {
  107. ptr = ptr -> next;
  108. }
  109. ptr -> next = new_node;
  110. new_node -> next = NULL;
  111. }
  112. return start;
  113. }
  114.  
  115. struct node * display(struct node *start) {
  116. int no=1;
  117. struct node *ptr;
  118. ptr = start;
  119. clrscr();
  120. printf("\t\t--- ITEM LIST ---\n\n");
  121. printf("------+-------------------+---------------+----------+-------+\n");
  122. printf("| No. | Name | Type | Quantity | Price |\n");
  123. printf("------+-------------------+---------------+----------+-------+\n");
  124. while (ptr != NULL) {
  125. printf("|");
  126. printf(" %-4d|", no);
  127. printf(" %-18s|", ptr -> name);
  128. printf(" %-18s|", ptr -> type);
  129. printf(" %-9d|", ptr -> qty);
  130. printf(" %-6d|\n", ptr -> price);
  131. ptr = ptr -> next;
  132. no++;
  133. }
  134. printf("------+-------------------+--------+----------+-------+\n");
  135. return start;
  136. }
Advertisement
Add Comment
Please, Sign In to add comment