Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.shimage text in transcribed 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

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_2

Step: 3

blur-text-image_3

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

Big Data, Mining, And Analytics Components Of Strategic Decision Making

Authors: Stephan Kudyba

1st Edition

1466568704, 9781466568709

More Books

Students also viewed these Databases questions

Question

16.3 Describe the purpose of Canadian labour laws.

Answered: 1 week ago

Question

Write a Python program to check an input number is prime or not.

Answered: 1 week ago

Question

Write a program to check an input year is leap or not.

Answered: 1 week ago

Question

8. Provide recommendations for how to manage knowledge.

Answered: 1 week ago