现有一个结构体,里面有多种数据类型,然后我想用fread函数读取txt赋值给这个结构体。
Student1
500
100 80 100 80 100 80 100 80
100 80 100 80 100 80 100 80
100 80 100 80 100 80 100 80
100 80 100 80 100 80 100 80
100 80 100 80 100 80 100 80
这是我的txt文件内容,代码如下,调试结果为所有东西全部在char name[10]中,int类型的变量没有值,好久没用过C了,不知道问题出在哪里?
#include "stdafx.h"
#include <stdlib.h>
struct scoreinfo
{
int wscore;
char name[7];
int inter[5][8];
}*p;
int _tmain(int argc, _TCHAR* argv[])
{
struct scoreinfo *p;
p=(struct scoreinfo*)malloc(sizeof(struct scoreinfo));
FILE *fp;
fp=fopen("Student1.txt","rb");
int j=sizeof(scoreinfo);
fread(p,sizeof(scoreinfo),1,fp);
fclose(fp);
return 0;
}