判断单词的数量可以用空格来进行,代码如下:
#include<stdio.h>
int main()
{
int i, c, num = 1;
char string[81];
gets(string);
for (i = 0; (c = string[i]) != '0'; i++)//因为数组最后一位是’0’
{
if (c == ' ')//用空格来判断单词
num++;
}
printf("there are %d words in the lines\n", num);
return 0;
}