#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char s[80];
cout<<"输入一行文字:";
cin>>s;
char *p;
p =s;
int n = strlen(s);
int sum1=0;
int sum2=0;
int sum3=0;
int sum4=0;
int sum5=0;
for(p=s;*p!='\0';p++){
if(*p>='0'&&*p<='9') sum1++;
else if(*p >= 'a'&&*p <= 'z') sum2++;
else if(*p >= 'A'&&*p <= 'Z') sum3++;
else if(*p == ' ') sum4++;
else sum5++;
}
cout<<"数字个数为:"<<sum1<<endl;
cout<<"小写字母个数为:"<<sum2<<endl;
cout<<"大写字母个数为:"<<sum3<<endl;
cout<<"空格个数为:"<<sum4<<endl;
cout<<"其他字符个数为:"<<sum5<<endl;
return 0;
}
有问题 待改善