Question: #include int totalWordCount ( char * filename, int max _ word _ length ) { / / If the file cannot be found, return -
#include int totalWordCountchar filename, int maxwordlength
If the file cannot be found, return
fptr fopenfilenamer;
if fptr NULL
return ;
Dynamically allocate a string of length maxwordlength
Read words to that string, using fscanf, and count the words
Hint: fscanffileptrs mystring will retrieve everything up to the next whitespace up to characters add a
Close the file and free the string
Return the word count
Inputs:
char filename The name of the input file
int maxwordlength The longest any word is allowed to be
int totalwordcount The total number of words in the file
void eachWordCountchar filename, int maxwordlength, int totalwordcount
Open the file
If fopen fails, return
Dynamically allocate space for your table of words, both words and ints to act as word counts
Hint: you can use pointer arithmetic or double pointers to navigate your table of words
Hint: you may want a variable to track how many rows of your table contain real data
Read in words from the file
convert them to lowercase using the
if the word does not appear in the table, add it and give it a count of
if the word does appear in the table, increment its count
Hint: you can use strcmp to compare if two strings are identical
Close the file
Print out words and their counts
Free all dynamically allocated memory
This assignment counts the number of words in a file, allocates space for a list of these words, then goes back
through the file to identify all the distinct words and count how many times each distinct word occurs.
For example, given a file containing the phrase:
Fool me once, shame on you. Fool me twice, shame on me
The program would count the words. There are twelve words. Then it would make space for a table of twelve
words and numbers. Then it would go through the file and look at each word:
"Fool" would be added to the table with count
Me would be added to the table with count
"Once" would be added to the table with count
"Shame" would be added to the table with count
On would be added to the table with count
"You" would be added to the table with count
"Fool", already being in the table, would get count
Me already being in the table, would get count
"Twice" would be added to the table with count
"Shame", already being in the table, would get count
On already being in the table, would get count
Me already being in the table with count would get count
The program would then print out: fool me once shame on you twice
You may notice that the phrase input has punctuation and capital letters, while the table of output does not. A
function is provided to convert all words that is blocks of characters separate by spaces into their dictionary
form lowercase letters only
This output will be sorted that is to say, the lines will be alphabetized before being compared with a correct
answer, so it's okay if your program prints things in a different order. Check Memory Leak
Your program must not crash and must not leak memory. The leaked bytes will accumulate across all test cases in
each assignment. If your program leaks memory, it is very likely that you will receive zero. Please use valgrind to
check memory errors. A program that leaks memory is like an airplane that leaks fuel. Neither can be accepted.
WHAT TO SUBMIT
Submit the following files to gradescope as a zip file: 'main.c 'filestr.c 'filestr.h
Efficiency
It may seem like your program takes up a lot of empty space with its word table, and searches inefficiently through
that table to see if a word has already been added. In ECE you'll learn about more advanced data structures
and algorithms that will help conserve space and time.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
