免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 713 | 回复: 1
打印 上一主题 下一主题

关于文件的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-11-22 11:18 |只看该作者 |倒序浏览
各位大虾帮帮忙,我已经不行了
我在文件读写的时候总是不对,比如:
add_new()
{int count;
char flag='y';
struct student{int     code;
                        char   name[20];
                        int      age;
                      };
struct student study;
FILE*fp;
if((fp=fopen("item","a+"==NULL))
  { getchar();
     exit(0);
  }
int count;
fread(&count,sizeof(int),1,fp);
fwrite(&count,sizeof(int),1,fp);
while(flage=='y')
{count++;
  printf("enter code,name,age:"
  scanf("%d\t%s\t%d\t",&study.code,study.name,study.age);
  fwrite(&study,sizeof(struct student),1,fp);
  printf("\n add another?";
  scanf("%c",flag);
}
rewind(fp);
fwrite(&count,sizeof(int),1,fp);
fclose(fp);
if((fp=fopen("item","a+"==NULL))
  { getchar();
     exit(0);
  }
int count_1;
fread(&count_1,sizeof(int),1,fp);
printf("%d",count_1);
fseek(fp,sizeof(struct student)*2,1);
fread(&study,sizeof(struct student),1,fp);
printf("%d\t%s\t%d\t",study.code,study.name,study.age);
}
输出结果总是不对,各位大虾帮忙看一下

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
2 [报告]
发表于 2004-11-22 12:29 |只看该作者

关于文件的问题

错误提示,另外,代码用论坛的code功能编辑以显示缩进。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP