Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. //Justin Nelson
  2. //Linked list program.
  3.  
  4. char menu();
  5.  
  6. #include <stdio.h>
  7.  
  8. struct Inventory
  9. {
  10. int number;
  11. int qty;
  12. float price;
  13. struct Inventory *next;
  14. };
  15.  
  16. typedef struct Inventory Inv;
  17.  
  18. int main()
  19. {
  20. struct Inventory *first = NULL, *previous = NULL, *current = NULL;
  21. char menuChoice;
  22. int x, i;
  23. float y;
  24. struct Inventory number, qty, price;
  25.  
  26. //menuChoice = menu();
  27. //printf("\n%c", menuChoice);
  28. for (i = 0; i < 3; i++)
  29. {
  30. current = (struct Inventory*) malloc(sizeof(struct Inventory));
  31. printf("Enter the part number: ");
  32. scanf("%d", current -> number);
  33. //current -> number = x;
  34. printf("%d", current->number);
  35. printf("Enter the quantity: ");
  36. scanf("%d", &x);
  37. current -> qty = x;
  38. printf("Enter the price: ");
  39. scanf("%f", &y);
  40. current -> price = y;
  41. if (first = NULL)
  42. {
  43. first = current;
  44. previous = current;
  45. }
  46.  
  47. previous->next = current;
  48. current -> next = NULL;
  49. previous = current;
  50.  
  51. }
  52.  
  53. current = first;
  54. while (current != NULL)
  55. {
  56. printf("Part Number: %d\tQuantity: %d\tPrice: %f", current->number, current->qty, current->price);
  57. }
  58.  
  59. return 0;
  60. }
  61.  
  62.  
  63. char menu()
  64. {
  65. char choice;
  66.  
  67. printf("Select one of the following.\n\n");
  68. printf("A. Create a new linked list of part number, quantity and price.\n");
  69. printf("B. Add to an existing list (read from a file)\n");
  70. printf("C. Print the entire list.\n");
  71. printf("D. Print the information for one user selected part number.\n");
  72. printf("E. Insert a new structure into the linked list.\n");
  73. printf("F. Modify an existing structure into the linked list.\n");
  74. printf("G. Delete an existing structure from the list.\n");
  75. printf("H. Save a list (to a file)\n");
  76. printf("I. Exit from the program.\nYour selection: ");
  77. scanf("%c", &choice);
  78.  
  79. return choice;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement