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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With