Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Heap programming (50 Points) Please complete the C program below that puts items on the command line (except for the program name itself) into a
Heap programming (50 Points)
Please complete the C program below that puts items on the command line (except for the program name itself) into a linked list, prints that list, and then 'free()'s it.
You must use struct Node provide!
/*-------------------------------------------------------------------------* *--- ---* *--- argList.c ---* *--- ---* *--- This program assembles the command line arguments into a ---* *--- linked list. The linked list is printed, and then free()d. ---* *--- ---* *--- ---- ---- ---- ---- ---- ---- ---- ---- ---* *--- ---* *--- Version 1a i Joseph Phillips ---* *--- ---* *-------------------------------------------------------------------------*/ #include#include #include // PURPOSE: To hold a node in a linked list of strings. struct Node { char* namePtr_; struct Node* nextPtr_; }; // PURPOSE: To create and return a linked list of strings from 'argv[1]' to // 'argv[argc-1]', or to return 'NULL' if 'argc' <= 1. struct Node* makeList (int argc, char* argv[] ) { struct Node* list = NULL; struct Node* end = NULL; int i; for (i = 1; i < argc; i++) { // YOUR CODE HERE } return(list); } // PURPOSE: To print the 'namePtr_' values found in 'list'. No return value. void print (const struct Node* list ) { const struct Node* run; // YOUR CODE HERE } // PURPOSE: To do nothing if 'list' is NULL. Otherwise to 'free()' both // 'nextPtr_' and 'namePtr_' for 'list', and all of 'nextPtr_' successors. // No return value. void release (struct Node* list ) { // YOUR CODE HERE } // PURPOSE: To create, print, and 'free()' a linked list of the 'argc-1' // items on 'argv[]', from 'argv[1]' to 'argv[argc-1]'. Returns // 'EXIT_SUCCESS' to OS. int main (int argc, char* argv[] ) { // I. // II. : struct Node* list; list = makeList(argc,argv); print(list); release(list); // III. Finished: return(EXIT_SUCCESS); }
Sample output:
$ ./argList hello there hello there $ ./argList hello there class hello there class $ ./argList $
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started