2

我尝试用 C 输出字符列表: http ://www.alt-codes.net/

for (i=0; i<len; i++){
    printf("%d\t: %c", i, i);
}

我得到的所有非 ASCII 字符的问题?在 Ubuntu 上工作。

我怎样才能以很好的方式输出它们。

4

4 回答 4

1

The formatting will be poor, but apart from that the code you posted works.

ASCII characters 0-31 are various space characters and there is no standardized way to print them. The link you posted is a common, yet non-standard "extended ASCII table". There is no guarantee that those exact symbols will be printed on your particular platform.

They work fine for me in Windows 7, tested with GCC and Embarcadero C++, both print those symbols. But on another OS and/or compiler, different symbols or nothing at all might be printed.

Only ASCII characters 32 - 126 are guaranteed to be printable, and the same symbol, on all systems.

于 2012-10-24T14:12:45.910 回答
0

各种 ASCII 字符,例如许多低于 32 的字符,是不可打印的。在打印之前,您需要将不可打印的内容翻译成其他内容(例如空格)。

请注意,您链接到的 ALT 代码不是 ASCII 代码。

于 2012-10-24T14:08:44.090 回答
0
于 2012-10-24T14:11:38.270 回答
0

Depending on your needs, you can take the approach of an hexadecimal editor and print only those characters that have a graphical representation, for that purpose you can use isprint() or isgraph() (the latest is essentially the same as isprint() but don't print the space) defined in ctype.h, for example:

for (i = 0; i < len; i++) {
    printf("%d\t: %c", i, isprint(i) ? i : '.');
}
于 2012-10-24T14:53:40.653 回答