问题的关键是怎么确定出现了新的单词
#include<stdio.h>
int main(void)
{
char string[20] = { "i am a boy" };
int i, count = 0, word = 0;
char c;
for (i = 0; (c = string[i]) != '\0'; i++)
{
if (c == ' ')
{
word=0;
}
else if(word==0)
{
word = 1;
count++;;
}
}
printf( "%d\n",count );
return 0;
}