Error On Fseek
Contents |
in a stream SYNOPSIS #include <stdio.h>
int fseek(FILE fseek example *stream, long offset, int whence);
[CX] Fseek Seek_end
src="../images/opt-start.gif" alt= "[Option Start]" border="0"> int fseeko(FILE *stream, off_t offset, int whence); Fseek Backwards
End]" border="0"> DESCRIPTION [CX] The functionality described on this reference page is aligned with the ISOC standard. Any conflict between the requirements described here
Fseek Negative Offset
and the ISOC standard is unintentional. This volume of IEEEStd1003.1-2001 defers to the ISOC standard. The fseek() function shall set the file-position indicator for the stream pointed to by stream. If a read or write error occurs, the error indicator for the stream shall be set and fseek() ftell fails. The new position, measured in bytes from the beginning of the file, shall be obtained by adding offset to the position specified by whence. The specified point is the beginning of the file for SEEK_SET, the current value of the file-position indicator for SEEK_CUR, or end-of-file for SEEK_END. If the stream is to be used with wide-character input/output functions, the application shall ensure that offset is either 0 or a value returned by an earlier call to ftell() on the same stream and whence is SEEK_SET. A successful call to fseek() shall clear the end-of-file indicator for the stream and undo any effects of ungetc() and ungetwc() on the same stream. After an fseek() call, the next operation on an update stream may be either input or output. [CX] If the most recent operation, other than ftell(), on a given s
fsetpos, ftell, rewind - reposition a stream SYNOPSIS top #include
Programming Boards C Programming fseek failing - Error: Invalid argument Getting started with C or C++ | C Tutorial | C++ Tutorial | C and C++ FAQ | Get a compiler | Fixes for common problems Thread: http://cboard.cprogramming.com/c-programming/115669-fseek-failing-error-invalid-argument.html fseek failing - Error: Invalid argument Thread Tools Show Printable Version Email this Page… Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode 05-07-2009 #1 avi2886 View Profile View Forum Posts Registered User Join Date Feb 2009 Posts 26 fseek failing - Error: Invalid argument 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 error on 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.. error on fseek 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.. **/ 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. 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 Last edited by avi2886; 05-07-2009 at 04:57 PM. Reason: Grammar fault.. wrote hitting EOF instead of not hitting eof 05-07-2009 #2 quzah View Profile View Forum Posts ATH0 Join Date Oct 2001 Posts 14,826 What is 4 * 2960 * 181376 ? Does that fit in a 32bit int? Quzah. Hope is the first step on the road to disappointment. 05-07-2009 #3 nonoob View Profile View Forum Posts Registered User Join Date Sep 2008 Location Toronto, Canada Posts 1,835 Because when you go beyond row 181375, the offs