include stdio include string int wcount char int words space words spa

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <stdio.h>
#include <string.h>
int wcount(char *s) {
int words, space, c;
words = c = 0;
space = 1;
if (gets(s) && strlen(s) > 0) {
for (c = 0; c < strlen(s); c++) {
if (isspace(s[c])) {
if (!space) {
words++;
}
space = 1;
} else
space = 0;
}
if (!space)
words++;
}
printf("%d\n", words);
}
int main() {
char carray[128];
memset(carray, 0, 128);
wcount(carray);
}