Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

omplete the implementation of the word_count function, according to the following specification. program is required to read every character of a file which wi11 be

image text in transcribedimage text in transcribedimage text in transcribed

omplete the implementation of the word_count function, according to the following specification. program is required to read every character of a file which wi11 be connected to its standard input stream via redirection. It will count the er of characters in the file, along with the number of lines and the number of distinct words or the purpose of this exercise: The number of lines is defined to be the number of linefeed characters present in the file The number of words is defined to be the umber of times we move from a space, linefeed, or simi lar character, to any character that is not one of these o You can use library function isspace to find out if a character is one of these characters. o To keep things manageable, a other punctuation symbols will count as "word" characters. AMS will not test any of these characters. .To figure out you if you have moved from a space to a non-space, you can use a variable to remember the previous character. Copy the current char value into this variable after processing the current character, so the previous value will be available on the next iteration of the Loop general design of your program is as follows: Parameters: o The function expects no arguments. Returns: o The function produces no result (i. e. the return type is void) Process: o The process is generally similar to that of the previous formative question. o You will need additional counters for words and lines o When the program finishes, it should send the results to standard output, using the format: "Document contents: X lines; Y words; Z characters.", where X is the number of linefeed chars, Y is the number of words, and Z is the number of characters Notes .It is possible to get a significant fractional score by making smal1 adjustments to your solution to the formative exercise o Provided you get at 1east one of the correct values in the correct position in the output message, you will get some marks. o If you can successfully display the correct number of lines, the wrong number of words, and the correct number of characters, you will get more than half marks. The results produced by this program look similar to the following image It is possible to get a significant fractional score by making small adjustments to your solution to the formative exercise o Provided you get at least one of the correct values in the correct position in the output message, you will get some marks. o If you can successfully display the correct number of lines, the wrong number of words, and the correct number of characters, you will 1 1 get more than half marks. The results produced by this program look similar to the fol1owing image. bash $echo -n "1 9" | ./word count The document contains 8 lines, 9 words, and 17 characters Secho -n "1 WC 17 $echo -n "1 10 2 20 3 30 4 40 5 50 6 60 7 70 8 80 9 90" ./word count The document contains 8 lines, 18 words, and 44 characters echo -n "1 10 2 20 3 30 4 40 5 50 6 60 7 70 8 80 9 90" wc 18 You can redirect standard input using a pipe (), or by means of the void word countO // Insert your solution here int mainO word count return 0 AIS will run your program several times with different input sequences. The test harness will show the nput data which your program is tested with, along with the expected and actual values obtained by running the program ANS uses input redirection to send character data to your program, so if there is an error the input sequence n11 not show n he Expected and Actual parts of the error report. This is expected processing

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

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books

Students also viewed these Databases questions