求高手帮忙看看该怎么改才能不覆盖掉
程序代码:
#include <stdio.h> #define ESC 27 struct diary /*定义一个结构变量*/ { char name[8],weather[10],content[100]; struct { int month; int day; int year; }data; } main() {int i=0; struct diary user[10]; do { FILE *fp; fp=fopen("diary.txt","w+"); /*创建一个文件只写*/ printf("\nplease input your name:"); scanf("%s", user[i].name); /*输入姓名*/ printf("please input the data:");/*出入日期*/ scanf("%d%d%d",&user[i].data.month,&user[i].data.day,&user[i].data.year); printf("please input the weather:"); scanf("%s",user[i].weather); printf("please input content:"); scanf("%s",user[i].content); fprintf(fp,"Name : %s Data : %2d-%2d-%2d Weather : %s\nContent:\n%5s\n", user[i].name,user[i].data.month,user[i].data.day,user[i].data.year, user[i].weather, user[i].content); /*结果写入文件*/ fclose(fp); i++; }while(getch()!=ESC); }程序如上:创建一个TXT文件将内容写进去,当我用do while 循环再次写入内容 结果是写进去了但是覆盖了原先写的内容,求高手帮忙改下 谢谢了!!