给你个参考吧
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char ch;
int cout1=0,cout2=0;
int cout3=0,cout4=0;
printf("input the character ch:");
ch=getchar();
while(ch!='\n')
{
if (ch>='0'&&ch<='9')
cout1++;
else if (ch>='a'&&ch<='z'||ch>='A'&&ch<='Z')
cout2++;
else if (ch==' ')
cout3++;
else
cout4++;
ch=getchar();
}
printf("其中数字的个数:%d\n",cout1);
printf("其中字母的个数:%d\n",cout2);
printf("其中空格的个数:%d\n",cout3);
printf("其它的个数:%d\n",cout4);
return 0;
}