64,646
社区成员
发帖
与我相关
我的任务
分享
void 统计各类字符数量count(/*char a[]*/)
{
int D_num = 0, X_num = 0, num = 0, spen = 0, other = 0;
int i=0;
char a[10000];
gets_s(a);//while ((x = getchar()) != '\n')可读回车符
//for (i = 0; i <= (strlen(a) - 1); i++)
do
{
if (a[i] >= 'a' && a[i] <= 'z')
X_num++;
else if (a[i] >= 'A' && a[i] <= 'Z')
D_num++;
else if (a[i] >= '0' && a[i] <= '9')
num++;
else if (a[i] == ' ')
spen++;
else
other++;//包括对回车当字符统计
} while (a[i++]!='\0');
cout << "小写字符为:" << X_num<<"\t";
cout << "大写字母为:" << D_num << "\t";
cout << "数字为:" << num << "\t";
cout << "空格为:" << spen << "\t";
cout << "其他为:" << other << endl;
}