Description
写一个函数实现:输入一行字符,以空格分割单词,回车结束输入,输出单词的个数
输入样例
There are many students and many trees!
输出样例
7
#include <stdio.h>
#include <stdlib.h>
int main()
{
int count = 0, s = 0;
char c;
while((c = getchar()) != '\n')
{
if(!(((c <= 'z') && (c >= 'a')) || (c <= 'Z') && (c >= 'A')))
s = 0;
else if(s == 0)
{
s = 1;
count++;
}
}
printf("%d", count);
return 0;
}