#include <iostream>
#include <cstring>
using namespace std;
namespace tongji
{
int zimu=0;
int shuzi=0;
int kongge=0;
int qita=0;
}
int main()
{
char buf[120]=" ";
cout<<"请输入一条字符串"<<endl;
fgets(buf,120,stdin);
int res=strlen(buf);
for(int i=0;i<res-1;i++)
{
if((buf[i]>='A'&&buf[i]<='Z')||(buf[i]>='a'&&buf[i]<='z'))
{
tongji::zimu++;
}else if(buf[i]>='0'&&buf[i]<='9')
{
tongji::shuzi++;
}else if(buf[i]==' ')
{
tongji::kongge++;
}else tongji::qita++;
}
cout<<"该字符串中字母的个数是"<<tongji::zimu<<"个,"<<"数字的个数是"<<tongji::shuzi<<"个,"<<"空格的个数是"<<tongji::kongge<<"个,"<<"其他字符的个数是"<<tongji::qita<<"个."<<endl;
return 0;
}
10-21
6983
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-24
870
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)