Reading/Printing special characters in C

47 views Asked by At

I have Win11 and winlibs personal build version gcc-12.2.0-llvm-15.0.7-mingw-w64ucrt-10.0.0-r4. Im trying to read special croatian letters (č,ć,š,đ,ž) from stdin but program converts them to regular english letters (c,c,s,d,z).

Code:

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

#define MAXLINE 1000

int main() {
    wchar_t line[MAXLINE];
    setlocale(LC_ALL, "hr_HR.UTF-8");

    printf("Enter a line of text:\n");

    if (fgetws(line, MAXLINE, stdin) == NULL) {
        printf("Error reading input.\n");
        return 1;
    }

    wprintf(L"You entered: %ls", line);

    return 0;
}

Input and output:

Enter a line of text: šđčćžasd You entered: sdcczasd

Please, tell me what is the problem? Could it be due to compilers for windows. I tried to compile it with gcc and clang.

0

There are 0 answers