Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Incorrect output to the console in C

The purpose of the program is to get a symbol and then immediately display it on the screen. But the problem is that it outputs a different character, or nothing at all. I found that the output is in Windows-1251 encoding, and the input is in CP866. How do I solve this problem? How to make both output and input in Windows-1251 encoding.
Post Scriptum: the problem appears when you enter a Cyrillic character.

#include <stdio.h>
#include <stdlib.h>
#include <locale.h>

int main(void)
{
    setlocale(LC_ALL, "");

    printf("Уведіть символ.\n");

    char ch = getchar();

    printf("\n");

    printf("%c", ch);

    getchar();
    getchar();

    return 0;
}

I tried to use wchar_t ( respectively procedures wprintf(), getwchar(), but the situation did not change.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Maybe this will help?
https://stackoverflow.com/a/44167461/8893124
they suggest to set:

system("chcp 1251");
setlocale(LC_ALL, "UTF8");
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading