user3785768
user3785768

Reputation: 35

Convert user input to unicode

So, I'm trying to get some input from the user in a C program, doing fscanf(stdin, "%s", buffer) When I input the character å i get a value of 134 which corresponds to the codepage 437.

But when i use the windows function GetACP() i get 1252 as the active codepage and 134 doesn't match å in that codepage. I tried setting the codepage to UTF-8 but that didn't give me any input at all.

Is there a way of getting the corresponding codepage for user input and convert that to unicode format? Or if there's a better way of getting the input.

I've been looking around a lot and I can't find much info on this.

Upvotes: 0

Views: 242

Answers (1)

Mark Ransom
Mark Ransom

Reputation: 308138

The code page used by the console window is called the OEM code page for historical reasons. You can get the default code page with GetOEMCP and the currently selected code page with GetConsoleCP.

You can set the console to use UTF-8 with the command chcp 65001, but Microsoft does not guarantee it to work in all cases.

If you don't need normal C++ I/O to the console, you can use the Console Functions instead e.g. WriteConsoleW to output a Unicode string.

Upvotes: 1

Related Questions