鱼C论坛

 找回密码
 立即注册
查看: 3090|回复: 0

fread和fwrite的问题。我是新手!

[复制链接]
发表于 2013-11-5 21:56:24 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x

  1. #include "stdio.h"
  2. #include "stdlib.h"
  3. #define SIZE 1
  4. struct student
  5. {
  6. char name;       /*名字
  7. int age;             /*年龄
  8. int num;           /*学号
  9. char add;         /*地址
  10. }stu[SIZE];
  11. void main()
  12. {
  13. void save();   /*保存
  14. void load();   /*读取
  15. int i;
  16. printf("input name,age,num,add\n");
  17. for(i=0;i<SIZE;i++)
  18. {
  19. scanf("%s %d %d %s",&stu[i].name,&stu[i].age,&stu[i].num,&stu[i].add);
  20. }
  21. save();
  22. printf("do you need to read? \n1.YES\n2.NO\n ");
  23. int ch;
  24. scanf("%d",&ch);
  25. if(ch==1)
  26. {
  27. printf("there are name,age,num,add\n");
  28. load();
  29. for(i=0;i<SIZE;i++)
  30. {
  31. printf("%s %d %d %s",stu[i].name,stu[i].age,stu[i].num,stu[i].add);
  32. }
  33. }
  34. return;
  35. }
  36. void save()
  37. {
  38. FILE *fp;
  39. int i;
  40. if(!(fp=fopen("E:/tjf/cs/cheshi1","wb")))
  41. {
  42. printf("can not open");
  43. return;
  44. }
  45. for(i=0;i<SIZE;i++)
  46. {
  47. if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
  48. {
  49. printf("do not write");
  50. return;
  51. }
  52. }
  53. fclose(fp);
  54. }
  55. void load()
  56. {
  57. FILE *fp;
  58. int i;
  59. if(!(fp=fopen("E:/tjf/cs/cheshi1","rb")))
  60. {
  61. printf("can not read");
  62. return;
  63. }
  64. for(i=0;i<SIZE;i++)
  65. {
  66. if(!(fread(&stu[i],sizeof(struct sudent),1,fp)))
  67. {
  68. printf("do not read");
  69. return;
  70. }
  71. }
  72. fclose(fp);
  73. }
复制代码
QQ截图20131105215401.png
这是什么意思?
后面这句好像是错了,错哪了,求大神讲解!
if(!(fread(&stu[i],sizeof(struct sudent),1,fp)))
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-5-11 03:50

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表