Question: I'm writing a main program in C for assignment that adds, deletes, and searches within a linked list. The exit command is also used. I
I'm writing a main program in C for assignment that adds, deletes, and searches within a linked list. The exit command is also used.
I want to use fgets to get user input, but I'm not sure how to implement it. Per assignment specifications, the linked list has to be implemented using dynamic memory with a command like malloc. How would I use fgets with dynamic memory? I've only ever used it with an array of a specified size.
Here's the main program parameters:

Here's my main program code:


MAIN PROGRAM You should use the above functions to implement a main program which lets the user manipulate a linked list. It is important that the main program never manipulate the data structure directly. All manipulation should be done via the above routines (this is the idea of encapsulation/information hiding/ADTs) The first thing your program should do is initialize an empty linked list Next, the program should prompt the user for input using the prompt and then wait for the user to enter a command followed by the ENTER key. The program then processes the command, as follows: i number (where number is any legal integer) This will insert the number into the list, in order (smallest to largest), provided the node is not already in the list. It should then print the message "SUCCESS"; "NODE ALREADY IN LIST", or "OUT OF MEMORY." This will print the list in order, on one line, with the numbers separated by spaces s number This searches for the given number, and prints either "FOUND" or "NOT FOUND d number This deletes the node containing the given number, and prints either "SUCCESS" or "NODE NOT FOUND" This should cause the program to exit after freeing all allocated memory (use valgrind to confirm this) (anything else) should print a synopsis of legal commands. The program should return to showing a prompt, and wait for another command. #include
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
