Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Justin Nelson
- //Linked list program.
- char menu();
- #include <stdio.h>
- struct Inventory
- {
- int number;
- int qty;
- float price;
- struct Inventory *next;
- };
- typedef struct Inventory Inv;
- int main()
- {
- struct Inventory *first = NULL, *previous = NULL, *current = NULL;
- char menuChoice;
- int x, i;
- float y;
- struct Inventory number, qty, price;
- //menuChoice = menu();
- //printf("\n%c", menuChoice);
- for (i = 0; i < 3; i++)
- {
- current = (struct Inventory*) malloc(sizeof(struct Inventory));
- printf("Enter the part number: ");
- scanf("%d", current -> number);
- //current -> number = x;
- printf("%d", current->number);
- printf("Enter the quantity: ");
- scanf("%d", &x);
- current -> qty = x;
- printf("Enter the price: ");
- scanf("%f", &y);
- current -> price = y;
- if (first = NULL)
- {
- first = current;
- previous = current;
- }
- previous->next = current;
- current -> next = NULL;
- previous = current;
- }
- current = first;
- while (current != NULL)
- {
- printf("Part Number: %d\tQuantity: %d\tPrice: %f", current->number, current->qty, current->price);
- }
- return 0;
- }
- char menu()
- {
- char choice;
- printf("Select one of the following.\n\n");
- printf("A. Create a new linked list of part number, quantity and price.\n");
- printf("B. Add to an existing list (read from a file)\n");
- printf("C. Print the entire list.\n");
- printf("D. Print the information for one user selected part number.\n");
- printf("E. Insert a new structure into the linked list.\n");
- printf("F. Modify an existing structure into the linked list.\n");
- printf("G. Delete an existing structure from the list.\n");
- printf("H. Save a list (to a file)\n");
- printf("I. Exit from the program.\nYour selection: ");
- scanf("%c", &choice);
- return choice;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement