|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #include "stdio.h"
- #include "stdlib.h"
- #define SIZE 1
- struct student
- {
- char name; /*名字
- int age; /*年龄
- int num; /*学号
- char add; /*地址
- }stu[SIZE];
- void main()
- {
- void save(); /*保存
- void load(); /*读取
- int i;
- printf("input name,age,num,add\n");
- for(i=0;i<SIZE;i++)
- {
- scanf("%s %d %d %s",&stu[i].name,&stu[i].age,&stu[i].num,&stu[i].add);
- }
- save();
- printf("do you need to read? \n1.YES\n2.NO\n ");
- int ch;
- scanf("%d",&ch);
- if(ch==1)
- {
- printf("there are name,age,num,add\n");
- load();
- for(i=0;i<SIZE;i++)
- {
- printf("%s %d %d %s",stu[i].name,stu[i].age,stu[i].num,stu[i].add);
- }
- }
- return;
- }
- void save()
- {
- FILE *fp;
- int i;
- if(!(fp=fopen("E:/tjf/cs/cheshi1","wb")))
- {
- printf("can not open");
- return;
- }
- for(i=0;i<SIZE;i++)
- {
- if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
- {
- printf("do not write");
- return;
- }
- }
- fclose(fp);
- }
- void load()
- {
- FILE *fp;
- int i;
- if(!(fp=fopen("E:/tjf/cs/cheshi1","rb")))
- {
- printf("can not read");
- return;
- }
- for(i=0;i<SIZE;i++)
- {
- if(!(fread(&stu[i],sizeof(struct sudent),1,fp)))
- {
- printf("do not read");
- return;
- }
- }
- fclose(fp);
- }
复制代码
这是什么意思?
后面这句好像是错了,错哪了,求大神讲解!
if(!(fread(&stu[i],sizeof(struct sudent),1,fp)))
|
|