我是靠谱客的博主 直率小虾米,这篇文章主要介绍求输入字符串中各个字符的个数,现在分享给大家,希望可以做个参考。

如:输入1254zxaad+@ . .4

输出:数字5个,字母5个,空格2个,其他字符2个

#include <stdio.h>
int main()
{
	int digit,letter,other,kg;
	char ch;
	digit=letter=other=kg=0;
	printf("请输入一串字符:");
	ch=getchar();
	do
	{
		if((ch>='0')&&(ch<='9'))
			digit++;
		else if((ch>='a')&&(ch<='z')||(ch>='A'&&ch<='Z'))
	 		letter++;
		else if(ch==' ')
		 kg++;
			else
		other++;
	}
		while((ch=getchar())!='n');
	printf("数字%d个,字母%d个,空格%d个,其他%d个",digit,letter,kg,other);
	return 0;
 }

 运行结果如图:

 

 

最后

以上就是直率小虾米最近收集整理的关于求输入字符串中各个字符的个数的全部内容,更多相关求输入字符串中各个字符内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(51)

评论列表共有 0 条评论

立即
投稿
返回
顶部