C语言实验——单词统计
来源:百度知道 编辑:UC知道 时间:2024/05/31 14:42:37
从键盘输入一行字符,统计其中单词的个数,各单词以空格分隔,且空格数可以是多个。
Input
输入只有一行句子。仅有空格和英文字母构成。
Output
单词的个数。
Input
输入只有一行句子。仅有空格和英文字母构成。
Output
单词的个数。
#include "stdio.h"
void main()
{
char a[60];
int i,b=1;
printf("please input a chars:\n");
gets(a);
for(i=0;i<60;i++)
{
if(a[i]==' '&&a[i+1]!=' ')
b++;
}
printf("the number is %d\n",b);
}
//VC6.0编译