Hi all,
I have a file consisting of a huge array of floats written in binary mode (fwrite). Its actually a contiguous 2D array. I need to access various parts of the array and for this I use fseek to jump a different point and the fread to read in the data.
I noticed that some of my output coming out of the fread was arrays completely filled with only zeros. I could trace the problem to my fseek statement. For certain values of offset , my fseek just fails and checking errno gives me the error "Invalid argument". My code looks like this..
For the exact start row that I have set here.. 181375, the code works fine. But beyond that, 18376 onwards fseek fails and the error, as I already said, is reported as "Invalid argument". I was not able to find any information on why fseek would give an invalid argument error.Code:int start_row=18375, n_cols =2960, n_rows_to_read =9000; float *array; fp = fopen(filename, rb); array = (float*)malloc(n_rows_to_read*n_cols*sizeof(float) ); if( fseek(fp, start_row*n_cols*sizeof(float), SEEK_CUR) != 0) { perror("Fseekfailed"); exit(0); } /** fread and write into outfile.. **/
When I read in 9000 rows starting from 181375, the output is fine for all the 9000 rows after it. So I know for a fact that the file isn;t blank beyond row 181375. But if I am not hitting end of file why else would fseek give this error??
Appreciate any help from you guys..
thanks,
Avinash



LinkBack URL
About LinkBacks



