统计文章中单词个数

#include<stdio.h>
#include<assert.h>

int fun(const char* str)
{   
    assert(str != NULL);
    const char* p = str;
    int count = 0;//计数器
    while(*p != '\0')
    {
        if(*p != ' ' && (*(p+1) == ' ' || *(p+1) == '\0'))
        {
            count ++;
        }
        p++;
    }
    retrun count;
}

猜你喜欢

转载自blog.csdn.net/asjbfjsb/article/details/80721896