jaOjaa

another bs

Mar 13th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.36 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. struct node {
  7. struct node *next;
  8. char name[30];
  9. char brand[5];
  10. char type[20];
  11. char damage[20];
  12. struct node *prev;
  13. };
  14.  
  15. void clrscr() {
  16. system("@cls||clear");
  17. }
  18.  
  19.  
  20. struct node *start = NULL;
  21. struct node *create_ll(struct node *);
  22. struct node *display(struct node *);
  23. struct node *insert_end(struct node *);
  24. struct node *delete_beg(struct node *);
  25.  
  26. int main(int argc, char *argv[]) {
  27. int choice;
  28. do {
  29. clrscr();
  30. printf("PRINTER SERVICES\n");
  31. printf("++++++++++++++++++++++\n\n");
  32. printf("1. Service List\n");
  33. printf("2. Add Service\n");
  34. printf("3. Take Service\n");
  35. printf("4. Exit\n\n");
  36. printf("> Please input your choice : ");
  37. scanf("%d", &choice);
  38. switch(choice) {
  39. case 1: {
  40. start = display(start);
  41. getch();
  42. break;
  43. }
  44. break;
  45. case 2: {
  46. start = create_ll(start);
  47. getch();
  48. break;
  49. }
  50. break;
  51. case 3: {
  52. start = delete_beg(start);
  53. getch();
  54. break;
  55. }
  56. case 4: break;
  57. }
  58. } while(choice !=5);
  59. getch();
  60. return 0;
  61. }
  62. struct node *create_ll(struct node *start) {
  63. struct node *new_node, *ptr;
  64.  
  65. char name[25],brand[5],type[20],damage[20];
  66. int b=0;
  67. printf("\nInput Customer Name : ");
  68. fflush(stdin);
  69. scanf("%[^\n]",&name);
  70. do{
  71. printf("Input Printer's Brand [canon/epson/hp] : ");
  72. scanf("%s",&brand);
  73. if (strcmp("canon",brand)==0) {
  74. b=1;
  75. }
  76. else if (strcmp("epson",brand)==0) {
  77. b=1;
  78. }
  79. else if (strcmp("hp",brand)==0) {
  80. b=1;
  81. }
  82. else {
  83. b=0;
  84. }
  85.  
  86. } while (b==0);
  87.  
  88. do {
  89. printf("Input Printer's Type [4...20]: ");
  90. scanf("%s",&type);
  91. } while (strlen(type)<4 || strlen(type)>20);
  92.  
  93. do {
  94. printf("Input Damaged [5...20]: ");
  95. fflush(stdin);
  96. scanf("%[^\n]",&damage);
  97. } while (strlen(damage)<5 || strlen(damage)>20);
  98.  
  99. new_node = (struct node*)malloc(sizeof(struct node));
  100. strcpy(new_node->name,name);
  101. strcpy(new_node->brand,brand);
  102. strcpy(new_node->type,type);
  103. strcpy(new_node->damage,damage);
  104. if(start == NULL) {
  105. new_node->next = NULL;
  106. start = new_node;
  107. }
  108. else {
  109. ptr=start;
  110. while(ptr->next!=NULL) {
  111. ptr=ptr->next;
  112. }
  113. ptr->next = new_node;
  114. new_node->next=NULL;
  115. }
  116. return start;
  117. }
  118.  
  119. struct node *display(struct node *start) {
  120. int no=1;
  121. struct node *ptr;
  122. ptr=start;
  123. clrscr();
  124. printf("\nP R I N T E R S E R V I C E S\n===============================\n\n");
  125. printf("---------------------------------------------------------------------------------------------------------\n");
  126. printf("| No. | name \t\t|Printer's Brand | Type | \t Damaged |\n");
  127. printf("---------------------------------------------------------------------------------------------------------\n");
  128. while (ptr!=NULL) {
  129. printf("|");
  130. printf("%-6d |",no);
  131. printf("%-30s |",ptr->name);
  132. printf("%-18s |",ptr->brand);
  133. printf("%-20s |",ptr->type);
  134. printf("%-20s |\n",ptr->damage);
  135. ptr=ptr->next;
  136. no++;
  137. }
  138. return start;
  139. }
  140. struct node *delete_beg(struct node *start) {
  141. struct node *ptr;
  142. ptr = start;
  143. start = start -> next;
  144. start -> prev = NULL;
  145. free(ptr);
  146. return start;
  147. }
Advertisement
Add Comment
Please, Sign In to add comment