Question
Modify count.c so that it also prints the total number of words in the input text and the average word length. Print the average word
Modify count.c so that it also prints the total number of words in the input text and the average word length. Print the average word length with two digits to the right of the decimal point. Call your program avgWordLength.c. For the purpose of this assignment, assume that a word is a sequence of non-whitespace characters. The best way to test for a whitespace character is to use the library function isspace, which is in the library . For example, the function call isspace(c) returns 1 if char c is whitespace, and 0 otherwise. Do not use arrays. For an example of the program in action:
// count.c Count the number of lines and chars in the input. #include int main() { int lineCount = 0; int numLines = 0; int numChars = 0; printf("Enter text. Use an empty line to stop. "); while (1) { int ic = getchar(); if (ic ser@adminuser-VirtualBox-/Desktop/classDemos s gcc avgwordLength.c-o avgwordLength adminuser@adminuser-VirtualBox-/Desktop/classDemos$ ./avgwordLength Enter text. Use an empty line to stop. fgjglkk ofjvf abc Your text has 2 lines and 20 characters. Your text has 3 words, with an average length of 5.00. adminuser@adminuser-VirtualBox /Desktop/classDemosavgwordLength
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started