#include
#include
int count(char *s)
{
int i, ret;
i = 0;
ret = 0;
while (s[i++])
{
if (s[i] == ' ')
ret ++;
}
return ret;
}
int main()
{
char str[128];
fgets(str, 128, stdin);
printf("%d", count(str));
return 0;
}
哦也,如果是作业的话建议自己好好体会下每一句语句的意义..
#include "stdio.h"
#include "string.h"
main()
{ int i,count=0;
char s[80];
gets(s);
for(i=0;i<81;i++)
{ if(s[i]==' ')
count++;
}
printf("count=%d\n",count);
}