C语言作业在线等~~~~~~~~~~~~~~~~!!!!

来源:百度知道 编辑:UC知道 时间:2024/05/22 14:55:35
编写一个程序,从键盘输入一个字符串,统计此字符串中英文字母(alpha)、数字(digit)、空格(space)和其他(others)字符的个数,并输出结果

#include <stdio.h>
void main()
{
char str[1024],*p;
int alpha=0,digit=0,space=0,others=0;
gets(str);
for(p=str;*p;p++)
if(*p>='a'&&*p<='z') alpha++;
else if(*p>='A'&&*p<='Z') alpha++;
else if(*p>='0'&&*p<='9') digit++;
else if(*p==' ') space++;
else others++;
printf("Alpha:%d\nDigit:%d\nSpace:%d\nOthers:%d\n",alpha,digit,space,others);

}