bash 不显示 126 以上的扩展 ASCII 字符
我编写了一个小型 C 程序来打印与编译后的值 129 相对应的扩展 ASCII 字符
#include<stdio.h>
int main(void)
{
char a = 129;
printf("%c\n",a);
return(0);
}
,并在我的 unix 机器(fedora 16)的 bash 终端上运行它。 它给出了错误的显示。它在背面显示一个问号,背景为白色椭圆形。
事实上,如果我输入 a = 任何高于 126 的值,它都会显示相同的问号。
为什么会这样以及如何纠正?
I wrote a small c program to print an extended ASCII char corresponding to value 129
#include<stdio.h>
int main(void)
{
char a = 129;
printf("%c\n",a);
return(0);
}
compiled and run it on my unix machine (fedora 16) on bash terminal.
it gives wrong display. it shows a question mark in back with white oval background.
infact, if I put a = anything above 126, it is showing same question mark.
why so and how to rectify it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先,我怀疑这是 bash 的错; bash 只是找到您的程序并运行它,而实际显示程序的输出是终端应用程序的工作。其次,没有 127 以上的 ASCII 字符。尝试打印 128..255 范围内的字符将发出具有给定值的字节,但该字节的显示方式取决于您的终端及其配置方式。最有可能的是,您的终端希望所有程序输出都以 UTF-8 编码;为了与 ASCII 向后兼容,所有小于 128 的字节都是 UTF-8 中的有效字符,但是当涉及字节 128 及以上时,只有某些序列有效,并且具有高位设置的单独字节是错误的。尝试从单个程序按顺序打印字节 226、152 和 131;如果你看到一个雪人,你就会知道你的终端正在使用 UTF-8。
First of all, I doubt this is bash's fault; bash just finds your program and runs it, while actually displaying your program's output is the job of your terminal application. Secondly, there are no ASCII characters above 127. Trying to print a character in the range 128..255 will emit a byte with the given value, but how that byte gets displayed is determined by your terminal and how it's configured. Most likely, your terminal expects all program output to be encoded in UTF-8; for backwards compatibility with ASCII, all bytes less than 128 are valid characters in UTF-8, but when bytes 128 and above are involved, only certain sequences are valid, and a lone byte with its high bit set is an error. Try printing the bytes 226, 152, and 131, in that order, from a single program; you'll know that your terminal is using UTF-8 if you see a snowman.
为什么你认为有 127 以上的 ASCII 字符?
http://en.wikipedia.org/wiki/ASCII
ascii 基本上是 7 位,0- 127
why do you think that there are ascii chars above 127?
http://en.wikipedia.org/wiki/ASCII
ascii is basically 7 bit, 0-127
我编写了一个 bash 脚本来显示 ascii
0-127
+ 扩展128-255
。它取决于系统代码页、终端/控制台等。
字符 0 - 31、127 显示不可打印表中的代码。
所有其他都是打印到屏幕上的原始字符。
<代码>
<代码>
I wrote a bash script to display ascii
0-127
+ extended128-255
.It is dependent on the system code page, terminal/console, etc.
Chars 0 - 31, 127 display codes from a table for the non-printables.
All others are raw characters printed to screen.