设为首页 加入收藏

TOP

C语言-统计输出的文字有多少个单词
2014-11-23 21:34:02 来源: 作者: 【 】 浏览:1
Tags:语言 统计 输出 文字 多少 单词
题目:
    统计输出的文字有多少个单词
输入要求:
hello human ni hao
输出要求:
There are 4 words in the line
// 指针,可能会有点繁琐
#include 
  
   
int main()
{
	char a[999];
	char * e;
	int count = 0;
	gets(a);
	e = a;
	while(*e != '\0')
	{
		if( *e == ' ' || *e == '\t')
		{
			e++;
			continue;
		}
		if( (*e >= 'a' && *e <= 'z') || (*e >= 'A' && *e <= 'Z') )
		{
			count++;
			while(*e != '\0')
			{
				if( (*e >= 'a' && *e <= 'z') || (*e >= 'A' && *e <= 'Z') )
					e++;
				if( *e == ' ' || *e == '\t')
					break;
			}
		}
	}
	printf("您输入的有 %d 个单词\n", count);

	return 0;
}
  


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇c 字符串 转大写 下一篇C语言编写的娱乐小工具【小时钟、..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: