fseek function

Prototype int fseek (FILE * Stream, long int Offset, int Reference);
PurposeTo position the file pointer to a specified location
Header File#include <stdio.h>
Parameters
StreamPointer to an open FILE
OffsetByte count from Reference
Reference
SEEK_SETBeginning of file
SEEK_CURBeginning of file
SEEK_ENDEnd of file
Return Value
0Success
EBADFBad file pointer
EINVALInvalid argument
ESPIPEIllegal seek on device
  • These error number constants are defined in errno.h.
  • With streams not capable of seeking, the return value is undefined
Notes
  • fseek wipes out any previous ungetc.
  • for a stream opened in text mode, fseek may not function as expected unless positions returned by ftell are used.
  • fseek clears end-of-file.
  • The position specified can be beyond the end of the file.
Example #include <stdio.h> . . . FILE * Account_Master; long int Record_Number; int LRecl; . . . if (fseek (Account_Master, Record_Number * LRecl, SEEK_SET) == 0) printf ("Seek succeeded."); else printf ("Seek failed.");
Related functions
fopen fclose fread fwrite rewind ftell

c/c++ Index