#include <stdio.h>
int main(int argc, char *argv[]) {
FILE *fp = fopen("sss", "w+");
char buf[100];
fputs("hello, world", fp);
fflush(fp);
fgets(buf, 100, fp);
fputs(buf, stdout);
fclose(fp);
return 0;
}
有人可以教我我的代码有什么问题吗?以下是我的测试,但没有达到我的期望:
% clang test.c
% ./a.out
��h��%
% cat test.c
hello, world%
我的假设是这是字符编码的问题,但是当我使用fgets从现有文件中读取文本时,它可以正常工作。我所有的文件(和代码)都是用Emacs编写的,我不知道是什么原因导致输出乱码
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句