Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C code. Please complete by filling all ???s #include // include the header file that allows us to use dynamic memory management #include

C code. Please complete by filling all "???"s #include  // include the header file that allows us to use dynamic memory management #include  // predefine the maximum length of a word (i.e., Word_MAX_Length) using preprocessor // command "#define" #define ??? // define the structure WordFreq, which has a string variable word, an integer variable frequency // NOTE: we need to extend the structure by adding a struct WordFreq pointer variable next that // will be used for linked list struct WordFreq { ??? } WordFreq; // define function insert that inserts the parameter into the linked list void insert(struct WordFreq *); // define the head pointer of the linked list and initialize it with NULL value struct WordFreq * head = ??? ; void main(int argc, char * argv[]) { if (argc!=2) { printf("Please run as %s [filename] ", argv[0]); return; } // define a FILE pointer variable f ??? // try to open file with the file name given in command line argument and assign the // returned FILE pointer value to f. If the file cannot be opened, print "File (name) does // not exist ", where (name) is the file name given in command line argument if (??? ) { printf(??? ); return; } // define a struct WordFreq pointer variable line and dynamically allocate memory space // of the size of struct WordFreq to line ??? // check if the dynamic memory allocation is successful. If not, print "Cannot do dynamic // memory management " if (??? ) { printf(??? ); return; } printf("file content in %s: ", argv[1]); // read a line of word and frequency in the file into member variables of line and check if // it reaches the end of the file (EOF) while (fscanf(f, "??? ", line->word, ??? )!= ??? ) { // print the values of member variables word and frequency in variable line printf("%s %d ", ??? , ??? ); // initialize the value of member variable next in variable line by NULL ??? // call function insert to insert line into the linked list ??? // since the memory space pointed by line has been inserted into the linked list, // we need to dynamically allocate some other new memory space to line ??? // again, check if the dynamic memory allocation is successful. If not, print // "Cannot do dynamic memory management " if (??? ) { printf(??? ); return; } } // remember to free the memory space you've dynamically allocated to variable line ??? printf("content in the linked list: "); // traverse the linked list, print out each element and free its space // we stop until the value of head is NULL while (??? ) { // detach the first element in the linked list and put it into variable line // hint: let variable line point to the first element in the linked list and then move // the head pointer to point the next element in the linked list, which now // becomes the first element in the linked list ??? // print the values of member variables word and frequency in variable line printf("%s %d ", ??? , ??? ); // remember to free the memory space you've dynamically allocated to the // element just detached from the linked list, which is now pointed by line ??? } // remember to close the file pointed by f ??? } // remember we need to implement function insert void insert(struct WordFreq * element) { // we inserts the parameter element into the beginning of the linked list // hint: we let the member variable next of element point to the value that head point to. // We then let head point to the value pointed to by element ??? } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What factors contribute to career indecisiveness?

Answered: 1 week ago

Question

5. Structure your speech to make it easy to listen to

Answered: 1 week ago

Question

1. Describe the goals of informative speaking

Answered: 1 week ago