1
我学习C语言。我需要用Unicode数据创建一些文本文件。我已经写了这样的代码:文本文件中的本地化字符无效
#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);
}
,但我得到这样的结果:
??????, ???!
Hello, World!
为什么我没有得到俄罗斯字符?
请解释你如何查看我的gedit(Linux)的打开文件 – 2013-02-21 19:14:37
。 – 2013-02-21 19:19:46
gedit认为该文件是什么编码?它是否与实际编码匹配?如果你使用的是Linux,那么我怀疑UTF-8将是首选的编码方式。 – 2013-02-21 19:20:50