求助:帮忙看看此函数
为什实现不了,对文件中内容的修改,应该怎么做?????changebook()/*改变图书信息*/
{
FILE *fp,*fp2;
char bookname[10],choice;
int i;
fp=fopen("d:\\book.txt","r");
fp2=fopen("d:\\bookl.txt","w");
printf("please input yao xuigai de book's name\n");
scanf("%s",bookname);
for(i=0;fread(&book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(strcmp(book[i].bookname,bookname)==0)
{
printf(" this book's infor is:,please choice xui gai de nei rong\n");
printf(" num:%d name:%s writer:%s\n",book[i].booknum,book[i].bookname,book[i].bookcreat);
printf(" ......................................... \n");
printf(" | 1:xui gai book's num | \n");
printf(" | 2:xui gai book's name | \n");
printf(" | 3:xui gai writer | \n");
printf(" | please input1-3: | \n");
printf(" ......................................... \n");
scanf("%s",&choice);
switch(choice)
{
case '1':
{
printf(" please input new num\n");
scanf("%d",&book[i].booknum);
fwrite(&book[i],sizeof(struct book),1,fp2);
}break;
case '2':
{
printf(" please input new name\n");
scanf("%s",book[i].bookname);
fwrite(&book[i],sizeof(struct book),1,fp2);
}break;
case '3':
{
printf(" please input new writer\n");
scanf("%s",book[i].bookcreat);
fwrite(&book[i],sizeof(struct book),1,fp2);
}break;
defaut:printf(" wu ci cao zuo");break;
}
continue;
}
fwrite(&book[i],sizeof(struct book),1,fp2);
}
fclose(fp);
fclose(fp2);
fp=fopen("d:\\book.txt","w");
fp2=fopen("d:\\bookl.txt","r");
for(i=0;fread(&book[i],sizeof(struct book),1,fp2)!=0;i++)
{
fwrite(&book[i],sizeof(struct book),1,fp);
}
fclose(fp2);
fp2=fopen("d:\\bookl.txt","w");
fclose(fp2);
printf(" press anykey return\n");
getchar();
return 0;
}