写入字符串到文件
下面正确将"Hello,World!"写入文件,并再次打开读取出来的代码是
#include <stdio.h>
int main(int argc, char **args) {
// 写入
FILE *f1 = fopen("/tmp/hello.txt", "w+");
fputs("Hello,World!\n", f1);
fclose(f1);
// 读取
FILE *f2 = fopen("/tmp/hello.txt", "r+");
char buff[1024];
fgets(buff, 1024, f2);
fclose(f2);
// 打印
printf("%s", buff);
return 0;
}