Write C Language that will be able to open a file specified on the command line and process that. Your program should still be able to process from stdin but only if the given filename is '-'.this...







Write C Language that will be able to open a file specified on the command line and process that. Your program should still be able to process from stdin but only if the given filename is '-'.







this program will use an allocated struct to hold the word content and the occurrence count. The collection of word structs will be a a linked list stored in sorted order by the word content. Treat words as singleton's in your program - only one copy exists.







This program will also maintain a linked list for each line in the source file. Each line will be a linked list with a pointer to each word that appears in the line.







This should look for WC_DEBUG as an environment variable and if set to

true

should be treated as if -d option was provided on the command line.







Additional option to support will be:
-o

filepath

Specifies output file instead of stdout.










  1. Accept the path of the file to process as a command line argument. stdin can still be specified by using the file filename '-'.











  2. You are not required to dynamically allocate your input buffer.











  3. Your program should accept the following options on the command line with the accompanying meaning. Your program should accept multiple options in a single run:














-l -- report the line count (that is a lower case L) -c -- report the character count
-w -- report the word count
-f -- report each word and its frequency












-v -- reports all information (equivalent to all options -l -c -w -f)
-h -- prints a brief synopsis on how to use your program
-d -- print to stderr debugging information as your program progresses -o

filepath

-- Output report to file specified in

filepath

















  1. If no option is provided on the command line, your program should only report the word count. If options are provided, only print the requested values. Program still will require a file path or '-'.











  2. If you do not support more than a single file on the command line, you must exit with a usage message if more than one is detected.











  3. The report format should conform to YAML output of the following format. Indentation should be two spaces.














7.








my_file :











8.








word_count : 2











9.








line_count : 2











10.








char_count : 12











11.








word_frequency :











12.








word1 : 1











13.








word2 : 1














  1. For this version of the program, use a struct to store the word content and count.











  2. Use a linked list to manage your collection of word structs. Your linked list of words should be in order of the words in the file.











  3. All debugging or error messages should only be sent to stderr. Debug messages should note interesting events like new word found, old word counted, reallocating memory, etc.











  4. All normal output should be sent to the output stream specified with -o option or if absent to stdout.











  5. A word is a series of non-whitespace characters.











  6. A line is defined as a single linefeed character, 0x0A.











  7. The program frees all dynamically allocated memory when it is no longer required.











  8. All variables referencing freed memory are set to NULL accordingly.











  9. Your program should notify the user and exit with a 1 if your program can no longer process the stdin because of storage constraints.














Test:
































































How much wood could a woodchuck











chuck if a woodchuck











could chuck











wood?











Expected Output









































































































































































































































my_wc.test1.in :























word_count : 13






















line_count : 3






















char_count : 72






















word_frequency :






















how : 1






















much : 1






















wood : 1






















could : 2






















a : 2






















woodchuck : 2






















chuck : 2






















if : 1






















wood? : 1

















Apr 17, 2023
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here