Here are all of the requirements: Write a C program called wlf.c that reads text
ID: 3638236 • Letter: H
Question
Here are all of the requirements:Write a C program called wlf.c that reads text from the standard input and prints out a frequency table for the word lengths found in the text.
Your program should read from standard input and write to standard output.You are NOT supposed to use file operations (fopen, fclose and so on). To take a text file as input, use wlf < docs/Alice-in-Wonderland.txt
Your program should have at least two functions: one that processes a line at a time and one for printing the result table.
You must use malloc() or calloc() to create all your arrays and buffers.
Use fgets() for reading the input. The contents of the input text file can be read in your program using fgets(buffer, BUFFERSIZE, stdin). When fgets() returns a NULL, the end of the file has been reached.
Use strtok() for tokenizing. To keep this simple, we will use the string " ,.;:'"&!? -_ " as the delimiter string for strtok().
The output should consist of a table of word length followed by frequency. The table should only show the rows for non-zero frequencies. Show the average length as the last line of the output. See the sample output below. Depending on how you count new words, you may get slightly different results for a few of the input files provided in the doc directory.
The output is expected to be on standard output. This means you do NOT need to open a file (fopen) for writing purposes. You can use the ">" operator to save (redirect) the output of a program to a text file. Therefore, running something like wlf < docs/Alice-in-Wonderland.txt > results/Alice-in-Wonderland.txt.out will store the results of your program in a file called Alice-in-Wonderland.txt.out instead of printing it on the screen.
You can assume that the maximum length of a word is 50 characters.
Your program should compile with no warnings when compiled with the -Wall option.
Create a test script (test.sh) for this assignment which runs your program on each of the files in a directory specified by a command-line argument. If the files are located in a directory called docs, you would call the script with
./test.sh docs
The test script should contain a loop which iterates through all the files in the given directory.
For extra credit, add another loop to the test script which compares each of your output files to the corresponding output file in a specified solutions directory, (The solutions are in results directory of the provided zip file).
Use the command
diff -w $f $2/$filename
to compare the two files, assuming that your loop variable is named f and the name of the file is stored in a variable called filename. You'll need a second command-line argument to supply the solutions directory and you'll need to use the basename function to separate the file name from the path. Now your script generates output files and compares them with the solution files.
Add a new rule named run to the Makefile. This rule depends upon the build rule and it should invoke the testing script test.sh when the make program is invoked as make run. test.sh should be invoked with a directory named docs. If you added the extra-credit part for comparing your results to the official ones, use the name results for the location of the correct results.
Explanation / Answer
void displayMenu() { coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.