Answer the question
In order to leave comments, you need to log in
Character representation in char?
Sorry for the possibly stupid question.
Characters in ASCII are encoded with values from 0 to 255 (256 in total). The symbol ╬ has the code 206.
If you output
char c = "╬";
printf("%d", (int)c);
Answer the question
In order to leave comments, you need to log in
It's just that the char in the sling is signed, you convert it to uint8_t instead of int and there will be a correct value.
Use unsigned type for characters:
unsigned char c = '╬';
printf("%d", c);
Correction: characters in ASCII are encoded from 0 to 127, and char sign does not apply to them.
Anything beyond 127 is Latin-1, OEM, ANSI, UTF-8, anything but ASCII. They write that all this is called extended ASCII, but how can you talk about something if it is KOI-8, and other encodings.
The provided code is not portable. For example, in Windows 10 it is possible for old programs to turn on the UTF-8 encoding instead of all sorts of 1251 and 866. There your ╬ are encoded in a completely different way. Use only Unicode. The quality of the standard library varies between different programming languages and different compilers. If the standard library is bad, you will have to work through the API of the operating system until it comes to these giraffes.
It's good practice to find the console and write to it via Unicode APIs, and when you find a redirect, write UTF-8 bytes, ignoring ACP_OEM, etc., to quickly bury the zoo of everything other than Unicode.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question