#include <stdio.h> //包含输入输出头文件
int main()
{
char str[128]; //用来储存字符,最多127个字符,最后要放字符结束符'\0'
int alp=0,num=0,oth=0,spa=0;//用来计数
int i; //用来循环计数
printf("请输入字符串:");
scanf("%s",&str);
i=0; //初始化0
while(str[i]!='\0') //字符串字符不是结束符时执行循环
{
if(str[i]<='z'&&str[i]>='a')alp++;//是小写字母
else if(str[i]<='Z'&&str[i]>='A')alp++;//是大写字母
else if(str[i]<='9'&&str[i]>='0')num++;//是数字
else if(str[i]==' ')spa++;//是空格
else oth++;//以上全不是
i++;
}
printf("%d %d %d %d\n",alp,num,spa,oth);//打印
return 0; //主函数返回,main标准都是返回int,一般0表示没有错误,非零表示有错误。
}
温馨提示:答案为网友推荐,仅供参考