fread 函数,为何读取不了值?如下代码,求解答!
#include<stdio.h>#include<stdlib.h>
#define SIZE 2
typedef struct
{
char name;
int num;
int age;
char addr;
}student;
student stu;
int i;
void load()
{
FILE *fp;
if(!(fp = fopen("dat.txt", "rb")))//打开文件
{
printf("Cannot open the file!");
return;
}
for(i = 0; i < SIZE; i++)
{
fread(&stu, sizeof(student),1 , fp);//读取数据块!
}
fclose(fp);
}
void main()
{
load;
for(i = 0; i < SIZE; i++)
{
printf("%s%d%d%s", stu.name, stu.num, stu.age, stu.addr );
}
}
页:
[1]