代码和要求不符吧?只求出了字符串中字母字符的数量,要求是单词的数量,要怎么改啊?

问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果

img

供参考:

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

可以试试以空格作为判断依据,单词数比空格数多一个