关于文件的问题
怎么修改已存在的文件
回复 楼主 瓦力
FILE *fp;fp=fopen("文件名","a");
向文件中加入新数据
程序代码:typedef struct book_ifo{
int num;
char writer[CHAR];
char name[CHAR];
double price;
struct book_ifo *next;
}BOOK;
BOOK *store(BOOK *head) //存储
{
FILE *fp;
BOOK *ptr, *p;
p = head;
if((fp = fopen("bookinfo.txt","w")) == NULL){
printf("File open error!\n");
exit(0);
}
for(ptr = head;ptr;ptr = ptr->next)
fprintf(fp,"%d %s %s %6.2lf\n",ptr->num,ptr->writer,ptr->name,ptr->price);
if(fclose(fp)){
printf("Can not close the file!\n");
exit(0);
}
return head;
}