C Now
fseek Function
C FILE Functions
Purpose
The fseek function is used to change the position of a file pointer (identified by FILE stream).
Header File
stdio.h
(fseek)
Prototype
int fseek (FILE * Stream, long int Offset, int Origin);
Arguments
- Stream
-
- Pointer to an open FILE structure
-
- Offset
-
- The (signed) number of bytes by which the file pointer is to be positioned from the origin.
-
- Origin
-
- The reference position. One of:
- SEEK_SET
- Beginning of file
- SEEK_CUR
- Current file position
- SEEK_END
- End of file
-
Return Values
- >=0
-
- Current number of bytes by which the file pointer is positioned from the origin..
-
- -1
-
- The seek failed.
-
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.");Codeexample
See Also
|
ftell |
Find a file pointer |
External Links
|
fseek |
HP 3000 Library Reference Manual |
|
fseek |
The Open Group Base Specifications |
|
fseek |
MSDN |
Copyright © 1999-2007, jhyoung,
revised 4/30/2007