输入一行文字,找出其中的大写字母。小写字母,空格,数字以及其他字符各有多少?

#include<stdio.h>
int main()
{
	char a[30];
	char *p;
	int i=0,j=0,m=0,n=0,k=0;
	p=a;
	printf("请输入一段文字:\n");
	gets(a);
	while(*p!='\0') //当字符不为结束符时,执行操作
	{
		if(*p>='A'&&*p<='Z')
		{i++;}
		else if(*p>='a'&&*p<='z')
		{j++;}
		else if(*p>='0'&&*p<='9')
		{m++;}
		else if(*p==' ') 
		{n++;}
		else
		{k++;}
		p++;  //执行完一轮后,将指针的地址指向下一个字符,继续检查
	}
	printf("大写字母:%d\n小写字母:%d\n数字:%d\n空格:%d\n其他字符:%d\n",i,j,m,n,k);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41722554/article/details/80427823
今日推荐