求教怎么实现:打开结构体文件并为其动态申请结构体数组的函数
这是我的一段代码,问题应该蛮多的,实在不知道怎么改了void open(FILE *fp,char*filepath)
{
if((fp=fopen(filepath,"rb+"))==NULL)
{
printf("cannot open file strike any key exit!!!!");
system("pause");
}
}
int BAbuild(FILE *fp,char*filepath,struct Basic *NAME)
{
open(fp,filepath);
fseek(fp,0,SEEK_END);
int N=ftell(fp)/sizeof(struct Basic);
NAME=(struct Basic*)malloc(N*sizeof(struct Basic));
rewind(fp);
return N;
}
void Basic_revise()//用于在main函数中调用
{
FILE *fp=NULL;
struct Basic *ba;struct Basic BASIC;ba=&BASIC;
int N=BAbuild(fp,"E:\\个人程序\\新建文件夹\\Basic_input.dat",ba);
fread(ba,sizeof(struct Basic),N,fp);
}
[此贴子已经被作者于2016-11-30 15:05编辑过]