求助,在线等
那位高人指导一下我的程序哪里出错了?总是dump.....我想读入一个dat文件,然后生成一个二进制文件。 原始的文件很简单,就是 010001010110001101010101010101010101010101 以下是我的程序
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct _HEADER {
int num1;
int num2;
int num3;
int num4;
}HEADER;
int i;
int x;
int y;
int z;
void readheader(HEADER *,FILE *);
void writeheader(HEADER *,FILE *);
main()
{
FILE *fp1;
FILE *fp2;
HEADER header;
short ***datatable;
fp1=fopen("g.dat","rb+");
fp2=fopen("newdata.dat","wb+");
readheader(&header,fp1);
for(x=0; x<2 ;x++){
for (y=0; y<3; y++){
for(z=0; z<4; z++){
fread(&datatable[x][y][z],sizeof(short),24,fp1);
fclose(fp1);
}
}
}
writeheader(&header,fp2);
for(x=0; x<2 ;x++){
for (y=0; y<3; y++){
for(z=0; z<4; z++){
fwrite(&datatable[x][y][z],sizeof(short),24,fp2);
fclose(fp2);
}
}
}
}
void readheader(HEADER *header,FILE *fp1)
{
fread(&(header->num1),sizeof(int),1,fp1);
fread(&(header->num2),sizeof(int),1,fp1);
fread(&(header->num3),sizeof(int),1,fp1);
fread(&(header->num4),sizeof(int),1,fp1);
}
void writeheader(HEADER *header,FILE *fp2)
{
fwrite(&(header->num1),sizeof(int),1,fp2);
fwrite(&(header->num2),sizeof(int),1,fp2);
fwrite(&(header->num3),sizeof(int),1,fp2);
fwrite(&(header->num4),sizeof(int),1,fp2);
}