#include <stdio.h>
#define N 128
int main(int argc, char *argv[])
{
char str[N];
int i = 0,word = 0,count = 0;
printf("please inuput a line of statements\n");
fgets(str,N,stdin);
while(str[i] != '\0')
{
if(str[i] == ' ')
{
word = 0;
}
else if(word == 0)
{
word = 1;
count++;
}
i++;
}
printf("There are words = %d\n",count);
return 0;
}
输入一行字符,统计其中有多少个单词。
最新推荐文章于 2023-11-27 20:30:34 发布