编写一个函数,从键盘输入一个字符串,分别统计其中的大写字母,小写字母以及数字的个数

来源:百度知道 编辑:UC知道 时间:2024/05/13 08:58:41

#include <iostream>
#include <string>
using namespace std;

int main(){
int low = 0, up = 0, num=0;
string s;
cout << "please enter a string: " << endl;
cin >> s;

for(string::size_type i = 0; i != s.size(); ++i)
{
if(isdigit(s[i]))
num ++;
else if(islower(s[i]))
low ++;
else
up ++;
}
cout << " The number of digit is: " << num << endl;
cout << " The number of lower character is: " << low << endl;
cout << " The number of upper character is: " << up << endl;

return 0;

}

我的编译环境是vc++6.0,能够得到正确结果。用c++编的。

#include <stdio.h>
void checkSum(char * s);
int main()
{
char szInput[1024];
gets(szInput);
checkSum(szInput);
return 0;
}

void checkSu