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