Question: Complete the implementation of the count_chars function, according to the following specification: Parameters: The function expects no arguments. Returns: The function

Complete the implementation of the count_chars function, according to the following specification:

• Parameters:

• The function expects no arguments.

• Returns:

• The function produces no result (i.e. the return type is void).

• Process:

• Declare an integer variable which will be used to count characters. Initialise the variable to zero.

• Enter a loop which continues indefinitely. Within the loop:

• Read a single character code from standard input. Do not prompt for input. This program is not designed for interactive use.

• If the character code is equal to EOF, break out of the loop.

• Otherwise, increment the counter by 1.

• This is the end of the loop.

• After the loop ends, display the number of characters processed.

Notes:

• The results produced by this program look similar to the following image.

• You can redirect standard input using a pipe (|), or by means of the <, <<, or <<< shell redirection operators. If you are not familiar with the concept, the following web search term will lead you to plenty of information sources: bash input redirection.

• Use this test driver to implement and test your function prior to submission.

Things to do:

• Insert your solution to the problem in the body of the count_chars function.

Things to avoid:

• Do not insert any code into the main function – any changes made to main will be discarded when AMS processes your submission.

Step by Step Solution

3.55 Rating (152 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The question involves developing a function called countchars to count the number of characters read from standard input until the endoffile EOF is re... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!