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
why wipro wase
can we implement multi-threads in c.
Can the curly brackets { } be used to enclose a single line of code?
When should structures be passed by values or by references?
What are the 4 types of functions?
What is wrong with this code?
What is indirection in c?
What is abstract data structure in c?
What is typeof in c?
Write a program on swapping (100, 50)
How can I send mail from within a c program?
What happens if header file is included twice?
Do character constants represent numerical values?
What is wild pointer in c?
How many main () function we can have in a project?