1. 程式人生 > >輸入字串,並對其大小寫和字元進行統計輸出

輸入字串,並對其大小寫和字元進行統計輸出

#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
#include<stdlib.h>

//輸入字串,並對其大小寫和字元進行統計輸出
//經分析,除了英文,其他都是字元。
void main(void)
{
	char Strs[100];
	int  BCount=0,SCount=0,CharChout=0,i=0;
	printf("請輸入一個字串:\r\n");
	gets(Strs);
	for (i = 0; i < 100; i++)
	{
		if(Strs[i]=='\0')
		{
			break;
		}
		//如果是大寫
		if(Strs[i]>='A'&&Strs[i]<='Z')
		{
			BCount++;
		}
		else if(Strs[i]>='a'&&Strs[i]<='z')
		{
			SCount++;
		}
		else
		{
			CharChout++;
		}
	}
	printf("您輸入的字串中:大寫%d個,小寫%d個,字元%d個!\r\n",BCount,SCount,CharChout);
	system("pause");
}