求助各位高手 编程问题

来源:百度知道 编辑:UC知道 时间:2024/05/31 15:16:07
我是菜鸟 这我们考试的题目 马上就要交上去了……还有半个小时……

题目:键盘上输入一行字符,统计出该行中的英文字母、空格、数字和其他字符的个数,并打印输出。

TC2.0的 请各位快点啦

#include <stdio.h>
#include <string.h>
#define MAX_LEN 1024

void main() {
int count_en;
int count_number;
int count_space;
int count_other;
char text[MAX_LEN];
int len;

count_en = count_number = count_space = count_other = 0;

scanf("%s", text);

len = strlen(text);

for (i=0; i<len; i++) {
if (text[i] <= 'Z' && text[i] >= 'A' || text[i] <= 'z' && text[i] >= 'a') {
count_en++;
} else if (text[i] == ' ') {
count_space++;
} else if (text[i] <= '9' && text[i] >= '0') {
count_number++;
} else {
count_other++;
}
}

/*now print result*/
printf("en char %d\n", count_en)