Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C 6.0 - <b>fsetpos() set stream position indicator</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 fsetpos()               Set Stream Position Indicator

 #include   <stdio.h>

  int fsetpos(stream, pos);
  FILE *stream;     Target stream
  fpos_t *pos; Position-indicator storage

    fsetpos() sets the position of the stream pointer to pos, which was
    previously obtained by fgetpos().

    Returns:    fsetpos() returns 0 if successful. If unsuccessful it
                returns a non-zero value and sets errno to one of the
                following manifest constants:

                    Constant   Meaning
                    --------   ------------------------------
                    EINVAL     The stream value is invalid
                    EBADF      The stream is not a valid file handle or
                               is not accessible

      Notes:    fsetpos() and fgetpos() are intended to  allow random
                access operation on files which are too large to handle
                with fseek() and ftell().

                fsetpos() clears the end-of-file indicator for the stream
                and undoes any effects of the ungetc() function on the
                same stream. After an fsetpos() call, the next operation
                on stream may be either input or output.

                The pos value is stored in an internal format and is
                intended for use only by the fsetpos() and fgetpos()
                functions.

   Portability:     ANSI

 -------------------------------- Example ---------------------------------

 This program reads data from a stream, saves the stream pointer position,
 reads more data, then returns to the saved position

           #include <stdio.h>

           FILE *stream;
           fpos_t *pos;

           main()
           {
              . . . open a stream
              . . . read some data

              /* get stream pointer position */
              if (fgetpos(stream, pos) != 0)
                  perror("Unable to get stream pointer position");

              . . . read some more data

              /* return to saved stream pointer position */
              if (fsetpos(stream, pos) != 0)
                  perror("Unable to set stream pointer position");
           }


See Also: fgetpos() fseek() ftell() fopen() fread() fwrite() ungetc()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson