VMS Help  —  CRTL  fseek
    Positions the file to the specified byte offset in the file.

    Format

      #include  <stdio.h>

      int fseek  (FILE *file_ptr, long int offset, int direction);

1  –  Arguments

 file_ptr

    A file pointer.

 offset

    The offset, specified in bytes.

 direction

    An integer indicating the position to which the offset is added
    to calculate the new position. The new position is the beginning
    of the file if direction is SEEK_SET, the current value of the
    file position indicator if direction is SEEK_CUR, or end-of-file
    if direction is SEEK_END.

2  –  Description

    The fseek function can position a fixed-length record-access
    file with no carriage control or a stream-access file on any
    byte offset, but can position all other files only on record
    boundaries.

    The available Standard I/O functions position a variable-length
    or VFC record file at its first byte, at the end-of-file, or on
    a record boundary. Therefore, the arguments given to fseek must
    specify any of the following:

    o  The beginning or end of the file

    o  A 0 offset from the current position (an arbitrary record
       boundary)

    o  The position returned by a previous, valid ftell call

    See the fgetpos and fsetpos functions for a portable way to seek
    to arbitrary locations with these types of record files.

                                 CAUTION

       If, while accessing a stream file, you seek beyond the
       end-of-file and then write to the file, the fseek function
       creates a hole by filling the skipped bytes with zeros.

       In general, for record files, fseek should only be directed
       to an absolute position that was returned by a previous
       valid call to ftell, or to the beginning or end of a file.
       If a call to fseek does not satisfy these conditions, the
       results are unpredictable.

    See also open, creat, dup, dup2, and lseek.

3  –  Return Values

    0                  Indicates successful seeks.
    -1                 Indicates improper seeks.
Close Help