Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C program that implements a Linked List of strings that will be read fro

ID: 3806764 • Letter: W

Question

Write a C program that implements a Linked List of strings that will be read from a file. It should display a menu that resembles the following:

1. Display Library

2. Check Out Item

3. Query for Author

4. Exit

The first step is to read in the entire library from the provided file (called library.txt). Use this file to create and populate your Linked List. Then, depending on the user’s selection, your program should respond appropriately. For example, if the user wishes to view the contents of the library, your program should iterate over the list and display each item. If they choose to check out a book from the library, your program should check if the book exists, and if so, remove it from the list and return it to the user. Finally, if the user chooses to query for an author, your program should return all the books found by that author. The program should build the library in sorted order based on author name. So each time a book is added, you should iterate over the list to put your book in the correct place.

library.txt file:

Explanation / Answer

#include #include #include void main() { struct node { int num; struct node *ptr; }; typedef struct node NODE; NODE *head, *first, *temp = 0; int count = 0; int choice = 1; first = 0; while (choice) { head = (NODE *)malloc(sizeof(NODE)); printf("Enter the data item "); scanf("%d", &head-> num); if (first != 0) { temp->ptr = head; temp = head; } else { first = temp = head; } fflush(stdin); printf("Do you want to continue(Type 0 or 1)? "); scanf("%d", &choice); } temp->ptr = 0; /* reset temp to the beginning */ temp = first; printf(" status of the linked list is "); while (temp != 0) { printf("%d=>", temp->num); count++; temp = temp -> ptr; } printf("NULL "); printf("No. of nodes in the list = %d ", count); }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote