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>fseek() repositions file pointer to given location</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 fseek()                 Repositions File Pointer to Given Location

 #include   <stdio.h>

 int        fseek(stream,offset,origin);
 FILE       *stream;                     Pointer to FILE structure
 long       offset;                      Number of bytes from origin
 int        origin;                      Initial position

    fseek() moves the file pointer for 'stream' to a new position
    'offset' bytes from 'origin'. After an fseek(), the next operation
    can be either a read or write, depending on how the file was opened;
    the operation takes place at the new position.  'origin' is one of
    the constants (defined in <stdio.h>) below:

               SEEK_SET           Beginning of file

               SEEK_CUR           Current position of file pointer

               SEEK_END           End of file

    SEEK_SET, SEEK_CUR, and SEEK_END are equivalent to the values 0, 1,
    and 2, respectively.

    Returns:    Zero if the pointer was successfully moved; non-zero on
                error.  The return value is undefined on devices that
                cannot seek (for example, terminals and printers).

      Notes:    With fseek(), the file pointer can be repositioned
                anywhere in or beyond the end of a file, but attempting
                to position the pointer before the beginning of the file
                causes an error.

                The CR-LF translations performed on a file opened in text
                mode make fseek() unreliable unless:

                    * The seek is performed with an offset of 0 relative
                      to any original values.

                    * The seek is performed from the beginning of the file,
                      using an offset value returned from a call to ftell().

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

    The following statements move the file pointer to the end of the
    file.

           #include <stdio.h>

           FILE *stream;
           int rslt;

           main()
           {
               if ((stream = fopen("data.txt","r+")) != NULL) {
                    rslt = fseek(stream, 0L, SEEK_END);
               }
           }



See Also: ftell() lseek() rewind()

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