统计字符串中的单词个数

img


请问第二个if是什么意思?

供参考:

#include<stdio.h>
#include<string.h>
int cntword(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 = cntword(s);
    printf("%d", cnt);
    return 0;
}