#include<stdio.h>
void main()
{
char string[99];
int i,num=0,word=0;
char c;
gets(string);
for(i=0;(c=string[i])!='\0';i++)
if(c==' ')
word=0;
else if(word==0)
{
word=1;
num++;
}
printf("There are %d word in the line.\n",num);
}
运行结果

本文介绍了一个使用C语言编写的程序,它通过`gets`函数读取输入的字符串,然后遍历并统计每行中的单词数量。程序核心在于判断字符是否为空格,以此来确定单词的边界。运行结果展示了字符串中单词的实际数量。
770

被折叠的 条评论
为什么被折叠?



