C语言一道编程题 各位帮帮忙

来源:百度知道 编辑:UC知道 时间:2024/05/09 07:09:12
从键盘上任意输入一个字符串,以换行符结束,请统计并输出这些字符串中的控制字符(不统计换行符),空格字符,数字字符,大写字母,小写字母和其他字符个数(不得使用数组)

#include <stdio.h>
#include <stdio.h>
int control,big,small,digit,space,other;
void count(char line[])
{
int i;
int n=strlen(line);
for(i=0;i<n;i++)
{
if(line[i]>='a'&&line[i]<='z')
small++;
else if(line[i]>='A'&&line[i]<='Z')
big++;
else if(line[i]>='0'&&line[i]<='9')
digit++;
else if(line[i]==32)
space++;
else if(line[i]>=0&&line[i]<32||line[i]==127)
control++;
else other++;
}
}
void main()
{
char line[1024];
int i;
printf("input :\n");
gets(line);
control=0;
big=0;
small=0;
digit=0;
space=0;
other=0;
count(line);
printf("control:%d,big letter:%d,small letter:%d,digit:%d,space:%d,others:%d\n",
control,big,small,digit,space,other);
}