c - using fwrite and double pointer to output 2D array to file -


i've dynamically allocated 2d array, accessed w/ double pointer, so:

  float **heat;   heat = (float **)malloc(sizeof(float *)*ti); // ti == 50   int n;   for(n = 0; n < ti; n++){ // ti == 50             heat[n] = (float *)malloc(sizeof(float)*sections); // sections == 30     } 

after filling of elements values (i'm sure filled correctly), i'm trying output file so:

fwrite(heat, sizeof(heat[ti-1][sections-1]), ((50*30)-1), ofp); 

i've tried:

fwrite(heat, sizeof(float), ((50*30)-1), ofp); 

am trying output 2d array right?

i know file i/o working (the file pointer ofp not null, , writing file in decimal works), strange characters , messages being outputted output file when try use fwrite write in binary.

i know heat[ti-1][sections-1] indeed within bounds of 2d array. using because know that's largest element i'm holding.

my output lot of nulls , strange system paths.

as know should use:

for(int n = 0; n < ti; n++) {   fwrite(heat[n], sizeof(float),sections, ofp); } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -