fread和fwrite的问题。我是新手!
#include "stdio.h"
#include "stdlib.h"
#define SIZE 1
struct student
{
char name; /*名字
int age; /*年龄
int num; /*学号
char add; /*地址
}stu;
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.name,&stu.age,&stu.num,&stu.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.name,stu.age,stu.num,stu.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,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,sizeof(struct sudent),1,fp)))
{
printf("do not read");
return;
}
}
fclose(fp);
}
这是什么意思?
后面这句好像是错了,错哪了,求大神讲解!
if(!(fread(&stu,sizeof(struct sudent),1,fp)))
页:
[1]