c++中如何字符串中如何计算空格

#include
#include
using namespace std;
int count(char str[])
{
int len;int f=0;
int a=0,b=0,c=0,d=0,e=0;//记得初始化 ,so important
len=strlen(str);
for(int i=0;i<len;i++)
{

            if(str[i]>='a'&&str[i]<='z')
    {
        b++;//计算小写字母的个数 
    }
   else if(str[i]>='A'&&str[i]<='Z')
   {
    a++;
   }
   else if(str[i]>='0'&&str[i]<='9')
   {
    c++;
   }
   else //if(str[i]==' '||str[i]=='\0'||str[i]=='.')
    {
        d++;
    }




}
e=a+b+c+d+f;//计算总的字符个数是多少,计算总的字符个数, 
cout<<a<<endl;
cout<<b<<endl;
cout<<c<<endl;
cout<<d<<endl;
cout<<e<<endl;
return 0;

}
int main()
{
int n=100;
char*c=new char[n];
for(int i=0;i {
cin>>c[i];
}
count(c);
delete []c;
// return 0;

}

char c =0x20; 代表的是空格字符

 #include<iostream>
using namespace std;
#include <stdio.h>
#include <string.h>
#include<stdlib.h>
int count(char str[])
{
    int len;int f=0;
    int a=0,b=0,c=0,d=0,e=0;//记得初始化 ,so important
    len=strlen(str);
    for(int i=0;i<len;i++)
    {
        if(str[i]>='a'&&str[i]<='z')
        {
            b++;//计算小写字母的个数 
        }
        else if(str[i]>='A'&&str[i]<='Z')
        {
            a++;
        }
        else if(str[i]>='0'&&str[i]<='9')
        {
            c++;
        }
        else if(str[i]==' ')//修改,计算空格
        {
            d++;
        }
    }
    e=a+b+c+d+f;//计算总的字符个数是多少,计算总的字符个数, 
    cout<<a<<endl;
    cout<<b<<endl;
    cout<<c<<endl;
    cout<<d<<endl;
    cout<<e<<endl;
    return 0;
}
int main()
{
    int n=100;
    char*c=new char[n];

    cin.getline(c,n);//修改,读入一行

    count(c);
    delete []c;
    // return 0;
}

楼主你好
3楼正解