数组中统计单词个数问题

1.为什么结果是统计的字母个数而不是统计单词的个数。
2.要怎么样才能使程序统计句子中单词的个数?
3.要怎么样才能同时输入多行英语句子?

img

统计句子里的单词数,单词间以空格间隔,供参考:

#include<stdio.h>
#include<string.h>
int cntword(char* s)
{
    int cnt = 0, flg = 1;
    char* p = s;
    while (*p) {
        if (*p == ' ')
            flg = 1;
        else if (flg) {
            cnt++;
            flg = 0;
        }
        p++;
    }
    return cnt;
}
int main()
{
    char s[512];
    int  cnt = 0;
    gets(s);
    cnt = cntword(s);
    printf("%d", cnt);
    return 0;
}