I am trying below code to print all the ASCII characters, but it does not print anything for 127 to 160. I know they are Control Chracters set or some Latin/ Spanish characters. If the same characters are copy pasted from Windows, it prints well in unix. Why not throug a C program?
#include <stdio.h>
int main()
{
int i;
char ch;
for(i = 0; i < 256; i++)
{
printf("\n%03d %02x %02c",i ,i ,i);
}
}
ASCII is a 7-bit code. The interpretation of byte values above 128 is dependent upon the OS, your locale/language settings, and so on. They are not standard. Under Windows in English, they are most commonly defined by CP1252; on Linux they are more commonly ISO-8859-1. Some OSs use UTF-8, which is not a character set itself but a way to encode Unicode into an 8-bit stream by using more than one byte for most characters. If you really need to work with characters outside the standard ASCII 32-126, you should really be using wide characters and locale stuff.
BTW, character 127 is a special case: it's the control character "rubout", which denotes erased data. (This was done so that a section of paper tape could be erased by punching all the holes!--yes, some of us are old enough to remember paper tape).
You might want to look into setlocale.
I don't know which set of characters you're looking for but you could try setlocale (LC_ALL,"");
to set your printed characters to match the environment (which seems to match your requirement since copy-pasting worked).
来源:https://stackoverflow.com/questions/16359225/how-to-print-extended-ascii-characters-127-to-160-in-through-a-c-program