It is possible that you are having a problem with the locales in the terminal you are running the program. If it is so, you only have to set the locale like this:
setlocale(LC_CTYPE,"");
More information here
Question
I learn the C language. I need to create some text file with Unicode data. I have wrote such code:
#include<stdio.h>
#include<stdlib.h>
#include<wchar.h>
int main(int argc, char *argv[]) {
wchar_t *s1 = L"Привет, мир!\n";
wchar_t *s2 = L"Hello, World!";
FILE *fp = fopen("./hello.txt", "w");
fputws(s1, fp);
fputws(s2, fp);
fclose(fp);
exit(EXIT_SUCCESS);
}
But I get such result:
??????, ???!
Hello, World!
Why I don't get the Russian chars?
Solution
It is possible that you are having a problem with the locales in the terminal you are running the program. If it is so, you only have to set the locale like this:
setlocale(LC_CTYPE,"");
More information here