使用 fwrite,我正在编写整个结构?我们在f1和f2?任何帮助,将不胜感激
typedef struct {
int field1;
int field2;
}mystruct;
int main(int argc,char *argv[])
{
int size=2;
mystruct structarray [size];
int i=0;
for (i=0;i<size;i++)
{
structarray[i]=calloc(1,sizeof(mystruct));
}
FILE *F1;
if (fopen("structfile","wt")==NULL){
err_sys("cannot be opened");
}
i=0;
for (i=0;i<size;i++)
{
structarray[i].field1=i;
}
fwrite(structarray[0].field1,sizeof(mystruct),size,F1);
fclose(F1);
}