#include<string>
using namespace std;
void Count(const char *pCh)
{
int char_count = 0;
int number_count = 0;
int space_count = 0;
int other_count = 0;
for(int n = 0; n < 15; n++)
{
if ('A' <= pCh[n] && pCh[n] <= 'Z' || 'a' <= pCh[n] && pCh[n] <= 'z')
char_count++;
else if( '0' <= pCh[n] && pCh[n] <= '9' )
number_count++;
else if(' ' == pCh[n] || '\n' == pCh[n])
space_count++;
else
other_count++;
}
cout<<char_count<<" 個字母"<<endl;
cout<<number_count<<" 個數字"<<endl;
cout<<space_count<<" 個空格或回車"<<endl;
cout<<other_count<<" 個其它字符"<<endl;
}
void main()
{
char chArray[15];
int nIndex = 0;
cout<<"請輸入 15 個字符:"<<endl;
while(nIndex < 15)
{
chArray[nIndex++] = getchar(); // getchar()才能接收空格和回車
}
Count(chArray);
}