69,369
社区成员
发帖
与我相关
我的任务
分享
int func(char *s)
{
int num=0;
/* s为空或者字符串长度为0,则单词数为0 */
if (s==null || *s==0) {
return num;
}
while (*s !=0) { /* 循环直到字符串末尾 */
while (' ' !=*s ) s++ ;/* 找单词, ;按照约定字符串第一个字母不应该是空格 */
num++; /*单词数加1 */
while (' '==*s) s++ ; /*跳过空格到下一个单词*/
}
return num;
}