Input is "Jack and jill went up a hill"
To print output is 1-letter word(s)-1
2-letter words-1
3-letter words-1
4-letter words-4

Answer Posted / bin

#include <stdlib.h>
#include <stdio.h>

int words[8];

int wordcount(char *string) {
int i;

for (i=0; *string; ++string) {
if (*string != ' ' && *string != '\t') {
++i;
} else {
words[i] += 1;
i = 0;
}
}
if (i) words[i] += 1;
}

int main()
{
int i;
char *str = "Jack and jill went up a hill";
wordcount(str);
for (i = 1; i < 5; ++i) {
printf("%d-letter word is - %d\n", i, words[i]);
}

}

Is This Answer Correct ?    42 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain what are binary trees?

614


why to assign a pointer to null sometimes??how can a pointer we declare get assigned with a garbage value by default???

1520


In which language linux is written?

606


What is the difference between text and binary modes?

648


What is the best way to comment out a section of code that contains comments?

785






What is volatile variable in c?

659


What is null pointer constant?

596


Why isnt any of this standardized in c?

640


What is the difference between strcpy() and memcpy() function in c programming?

628


What is printf () in c?

579


What is difference between main and void main?

630


How can I open a file so that other programs can update it at the same time?

664


how to introdu5ce my self in serco

1523


What is use of null pointer in c?

572


Explain how can a program be made to print the name of a source file where an error occurs?

691