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 / 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 |
If 4 digits number is input through the keyboard, Write a program to calculate sum of its 1st & 4th digit.
What are the usage of pointer in c?
What is the concatenation operator?
What are lookup tables in c?
What is the difference between CV and Resume ?
How the C program can be compiled?
Whats wrong with the following function char *string() { char *text[20]; strcpy(text,"Hello world"); return text; }
the portion of a computer program within which the definition of the variable remains unchanged a) mode b) module c) scope d) none
char ch="{'H','I',0};printf("%s",ch);what is output
Why dont c comments nest?
Can we assign string to char pointer?
Why is structure padding done in c?