从终端获取一个字符串,诀别统计其中大写字母、小写字母、数字及其它字符的个数

从终端获取一个字符串,分别统计其中大写字母、小写字母、数字及其它字符的个数。
//从终端获取一个字符串,分别统计其中大写字母、小写字母、数字及其它字符的个数。
#include<stdio.h>
#include<stdio.h>


int main(int argc,const char *argv[])
{
char str[100];
char ch;
int len,i;
int letter = 0, number = 0, space = 0, other = 0;
gets(str);
for(i=0;i<strlen(str);i++)
{
ch = str[i];
if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'))
{
letter++;
}
else if(ch>='0'&&ch<='9')
{
number++;
}
else if(ch==' ')
{
space++;
}
else
{
other++;
}
}
printf("letter=%d\nnumber=%d\nspace=%d\nother=%d\n",letter,number,space,other);
return 0;


}

版权声明:本文为博主原创文章,未经博主允许不得转载。