要求函数和指针解决各位大神教教我,写出来一点都不对
供参考:
#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;
}
不知道你这个问题是否已经解决, 如果还没有解决的话: