代码:
#include <stdio.h>
int Num(const char *s)
{
int count = 0;
while (*s != '\0')
if (*s ++ == ' ')
count ++;
return count;
}
int main ()
{
char s[200];
scanf("%[^\n]",s);
//gets(s); //有警告
printf("%d\n", Num(s));
return 0;
}
运行效果: