c语言怎么从文件里面读取中文啊
用了fscanf读取出来一片乱码,求大神指点一下,感谢感谢! $ lshello.txtmain.c
$ cat hello.txt
hello world
$ cat main.c
#include <stdio.h>
int main(void) {
FILE *fp = fopen("hello.txt", "r");
char buff;
fscanf(fp, "%s", buff);
puts(buff);
fclose(fp);
return 0;
}
$ gcc-debug -o main main.c
$ ls
hello.txtmainmain.c
$ ./main
hello
$ 读取的是数据,只要你读取的没毛病,看看你输出显示是不是支持中文环境 $ cat hello.txt
你好,世界!
$ cat main.c
#include <stdio.h>
int main(void) {
FILE *fp = fopen("hello.txt", "r");
char buff;
fscanf(fp, "%s", buff);
puts(buff);
fclose(fp);
return 0;
}
$ gcc-debug -o main main.c
$ ./main
你好,世界!
$
页:
[1]