【发布时间】:2014-07-08 06:38:29
【问题描述】:
我试图弄清楚为什么该程序不起作用。它将小写转换为大写,假设我输入“k”,它返回 K。然后我继续输入“A”,它不返回“a”,而是退出。但为什么?代码如下:
#include <stdio.h>
#include <stdlib.h>
int main(){
char UPPER,LOWER;
printf("Enter UPPERCASE\n");
UPPER = getchar();
if (UPPER >= 65 && UPPER <= 90)
{
UPPER = UPPER + 32;
printf("The UPPERCASE now is %c\n", UPPER);
}
printf("Enter lowercase\n");
LOWER = getchar();
if (LOWER >= 97 && LOWER <= 122)
{
LOWER = LOWER - 32;
printf("The lowercase now is %c\n", LOWER);
}
getchar();
getchar();
}
【问题讨论】:
-
当您在调试器中运行它或打印
UPPER和LOWER(BTW 变量名错误,请尝试upper和lower)它们的值是什么?