【发布时间】:2017-05-02 10:53:02
【问题描述】:
考虑以下 C 程序:
#include <stdio.h>
int main()
{
char c;
c = 65;
if(c=='A') printf("condition true");
return 0;
}
正如预期的那样(因为 A 的 ASCII 码是 65,所以这个程序打印语句“条件为真”)。
现在考虑以下 C 程序:
#include <stdio.h>
int main()
{
char c;
c = 27;
if(c==ESC) printf("condition true");
return 0;
}
由于 ESC 的 ASCII 码是 27,我希望这个程序也能打印语句“条件为真”。但是,程序甚至没有编译,而是返回了以下错误消息:
error: use of undeclared identifier 'ESC'
如何检查某个数字(例如 27)是否是某些特殊字符(例如 ESC、EOF、...)的 ASCII 码?
【问题讨论】:
-
这些特殊字符没有定义,可以使用
#define指令自己定义:#define ESC 27放在#include之后
标签: c char ascii special-characters