Here's a simple code to start with:
#include <stdio.h>
#include <locale.h>
#include <windows.h>
int main ()
{
unsigned char str [3];
printf ("LC_ALL:\t\t%s\n", setlocale (LC_ALL, ""));
printf ("LC_TYPE:\t%s\n", setlocale (LC_CTYPE, ""));
printf ("Input CP:\t%d\n", GetConsoleCP ());
printf ("Output CP:\t%d\n\n", GetConsoleOutputCP ());
str [0] = getchar ();
str [1] = getchar ();
str [2] = getchar ();
printf ("%d %d %d\n", str[0], str[1], str[2]);
printf ("%c %c %c\n", str[0], str[1], str[2]);
return 0;
}
Returned locale and encoding are represented on the picture. Let's say I input some small string: "пр", then press enter. What I expect are codes from OEM 866 encoding for 'п' and 'р', then 10 pointing at the end of the line, so the output codes are "175 224 10" - because console input encoding is 866, as returned by GetConsoleCP (). And I get what I expect.
Then I'm trying to output these characters to the console. What I expect are the same characters from input, because, as returned by 'GetConsoleOutputCP ()', the output encoding is 866. What I get are the characters from Windows-1251 encoding, which is returned by setlocale function.
So, does windows console output characters from locale codepage, but not from a codepage returned by GetConsoleOutputCP () function?
