fseek function
Prototype | int fseek (FILE * Stream, long int Offset, int Reference); |
Purpose | To position the file pointer to a specified location |
Header File | #include <stdio.h> |
Parameters |
Stream | Pointer to an open FILE |
Offset | Byte count from Reference |
Reference |
SEEK_SET | Beginning of file |
SEEK_CUR | Beginning of file |
SEEK_END | End of file |
|
|
Return Value |
0 | Success |
EBADF | Bad file pointer |
EINVAL | Invalid argument |
ESPIPE | Illegal 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
. . .
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 |
|