| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 354 人关注过本帖
标题:求助:帮忙看看此函数
取消只看楼主 加入收藏
lctontheway
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-5-4
收藏
 问题点数:0 回复次数:0 
求助:帮忙看看此函数
为什实现不了,对文件中内容的修改,应该怎么做?????
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;
}
搜索更多相关主题的帖子: 函数 
2008-09-04 18:34
快速回复:求助:帮忙看看此函数
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015762 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved