永发信息网

C语言作业:输入一串字母区分大小写和数字,要求分别输出大小写字母和数字以及个数,并按ESC退出。

答案:1  悬赏:30  手机版
解决时间 2021-01-25 04:53
  • 提问者网友:骨子里的高雅
  • 2021-01-24 23:58
C语言作业:输入一串字母区分大小写和数字,要求分别输出大小写字母和数字以及个数,并按ESC退出。
最佳答案
  • 五星知识达人网友:酒者煙囻
  • 2021-01-25 01:07
这种题该自己做吧。

#include <ctype.h>
#define MaxLen 255

int main() {
int upper, lower, digit, other, i;
char input[MaxLen];
char c;

upper = lower = digit = other = 0;
printf("Input a string: ");
scanf("%s", input);

for (i=0; i<strlen(input); i++) {
if (isupper(input[i]))
upper += 1;
else if (islower(input[i]))
lower += 1;
else if (isdigit(input[i]))
digit += 1;
else
other += 1;
}

printf("Upper: %d, Lower: %d, Digit: %d, Others: %d\n",
upper, lower, digit, other);
printf("Press ESC + Enter to exit.\n");

while(1) {
c = getchar();
if (c == 0x1B) exit(0);
}
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯