Question
Can you check my code and see if it needs addition or editing. Thank you. For Exercise 5.10, your program should read and store one
Can you check my code and see if it needs addition or editing.
Thank you.
For Exercise 5.10, your program should read and store one character at a time. (This way, it is not going to be limited to short strings.)
For the purpose of your program, a string is a non-empty sequence of characters that does not contain whitespace. Whitespace include the space character, the tab character, and the newline character. You may want to check the man page for the function is isspace in ctype.h, which will simplify the task of detecting whitespace in the text your program reads.
The key challenge in designing your program is coming up with a way to detect the transitions from string to spaces and vice versa. Several schemes are possible.
Write a test script test_string_mean.sh to help you test your program. You can simplify test_string_freq.sh to obtain your script.
Exercise 5.10. Write a program that reads strings from stdin and computes the integer mean of their lengths.
#include
#include
int main(){
char c;
intlength =0;
int =0;
int totalLength =0;
while( scanf("%c", 4c)!= EOF){
if ( isspace(c)==0) //inside the string
length++;
}
else{ //outside string
if(length !=0){
totalLength += length;
n++;
length =0;
}
if(n>0)
printf("_", totalLength);
printf("Nostring");
return 0;
}
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