求一个C语言程序!是 C语言哦!谢谢!急~

来源:百度知道 编辑:UC知道 时间:2024/06/15 12:42:01
题目描述

从键盘输入一行字符,统计其中空格的个数,各单词以空格分隔,且空格数可以是多个。

输入

输入只有一行句子。仅有空格和英文字母构成。

输出

单词的个数。

样例输入

stable marriage problem Consists of Matching members

样例输出

7

#include<stdio.h>
#define TRUE 1
#define FALSE 0
main()
{
char c;
int wcount=0,start=TRUE;
while((c=getchar())!='\n')
{
if(c==' ')
{
start=TRUE;
continue;
}
if(start==TRUE)
{
start=FALSE;
wcount++;
}
}
printf("%d\n",wcount);
}

你不是发过了吗?
还发?
-----------
#include<stdio.h>
void main()
{
int s=0;

char ch,pc=' ';
while((ch=getchar())!='\n')
{
if((ch!=' ')&&(pc==' '))
s++;
pc=ch;
}
printf("%d",s);
}

既然是要交作业的。。那我输入改一下- -