Monday, November 5, 2007

Writing arrays to binary files in C or C++

FILE *fp = fopen(filename, "wb+")
fwrite(&base_addr, dim_x*dim_y*sizeof(array_type), 1, fp);
fclose(fp);

//to read the same array back
FILE *fp = NULL;
type base_addr[dim_x][dim_y];
fp = fopen(filename, "rb");
fread(&base_addr, dim_x*dim_y*sizeof(array_type), 1, fp);
fclose(fp);

0 comments:

Post a Comment