你好我在尝试将数据写入文件时遇到了fopen和fputs。
特别是以下代码:
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE * fp;
fp = fopen ("file_out.txt", "a+");
fprintf(fp, "%s %s %s %d", "We", "are", "in", 2016);
fclose(fp);
return(0);
}
给我这个输出: 我们在2016年
这是我期待和希望的。
然而,当我改变
时fprintf(fp, "%s %s %s %d", "We", "are", "in", 2016);
到
fprintf(fp, "%s %s %s %d", "We", "are", "in", 3333);
并重新编译并运行我仍然获得与以前相同的输出!意思是,2016年印刷,而不是3333.非常感谢任何帮助。
答案 0 :(得分:0)
由于您已在附加模式white-space: nowrap
中打开文件,因此您编写的内容将附加到文件中。我想读取文件的实用程序只是读取文件的第一行。因此,您每次都会获得fp = fopen ("file_out.txt", "a+");
。