1.72米等于多少英尺:输入一字符串 输出其中大写,小写,数字的个数

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/01 16:45:43
提供完整原代码,谢谢!

不要依赖于ASCII码,用库函数来实现比较好。
void count(char *s)
{
int dig,upper,lower;
dig = 0;
upper = 0;
lower = 0;
while(*s1)
{
if (isupper(*s1)) upper++;
if (islower(*s1)) lower++;
if (isdigit(*s1)) dig++;
s1++;
}
printf("Upper=%d\n",upper);
printf("Lower=%d\n",lower);
printf("Digit=%d\n",dig);
}

先用函数算出该字符串算出其ASCII码,之后就好办了.

先用函数算出该字符串算出其ASCII码

CString::toupper
CString::tolower
CString::GetLength
三个函数够了吧

char str[100];
cout<<"输入一字符串:"<<endl;
cin>>str;
int count1,count2,count3,i;
count1=count2=count3=i=0;
while(str[i]!=0)
{
if(str[i]>=48&&str[i]<=57)count1++;
if(str[i]>=65&&str[i]<=90)count2++;
if(str[i]>=97&&str[i]<=122)count3++;
}
cout<<"数字个数:"<<count1<<endl;
cout<<"大写字母:"<<count2<<endl;
cout<<"小写字母:"<<count3<<endl;