#include <stdio.h>
int main(void)
{
char txt[] = "0"; //char * txt = "0" 只读 char txt[] = "0"可读可写
int num = 0;
int i = 0;
int j = 0;
int LetCount = 0;
int spaCount = 0;
int numCount = 0;
int othCount = 0;
printf("请输入一行字符:");
gets(txt);
while(txt[i] != '\0')
{
num = txt[i] + 0;//字符类型转数字类型
if(num >= 97 && num <= 122)
{
LetCount++;
}
else if(num >= 65 && num <= 90)
{
LetCount++;
}
else if(num == 32)
{
spaCount++;
}
else if(num >= 48 && num <= 57)
{
numCount++;
}
else
{
othCount++;
}
i++;
}
printf("输入的字符为:");
for(j=0;j<i;j++)
{
printf("%c",txt[j]);
}
printf("\r\n其中,中英文字母个数为: %d \r\n",LetCount);
printf(" 空格个数为: %d \r\n",spaCount);
printf(" 数字个数为: %d \r\n",numCount);
printf(" 其他字符个数为: %d \r\n",othCount);
return 0;
}