C语言实验——单词统计
Problem Description
从键盘输入一行字符(长度小于100),统计其中单词的个数,各单词以空格分隔,且空格数可以是多个。
Input
输入只有一行句子。仅有空格和英文字母构成。
Output
单词的个数。
Sample Input
stable marriage problem Consists of Matching members
Sample Output
7
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int i, len, num, t;
char a[101];
memset(a, 0, sizeof(a));
gets(a);
len = strlen(a);
num = 0;
t = 0;
for(i = 1; i < len; i++)
{
if(a[i] == ' ') t = 0;
//当字符为空格时,令t=0
else if(t &#