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>rewind() reposition file pointer to beginning of stream</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 rewind()                Reposition File Pointer to Beginning of Stream

 #include   <stdio.h>

 void       rewind(stream);
 FILE       *stream;                     Pointer to FILE structure

    rewind() moves the file pointer associated with 'stream' to the
    beginning of the file and clears the end-of-file and error
    indicators.  rewind() is equivalent to:

                   fseek(stream,0L,SEEK_SET)

    except that fseek() does not clear the end-of-file and error
    indicators.

    Returns:    No return value.

       Note:    Unlike rewind(), the return value from fseek() indicates
                whether or not the pointer was successfully moved.

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

    The following statements open a file, save the current file position,
    reposition the file pointer to the beginning of the file, then return
    to the saved position.

           #include <stdio.h>

           FILE *stream;
           int save_pos;

           main()
           {
               if ((stream = fopen("data.txt","r+")) != NULL) {
                    save_pos = ftell(stream);
                    rewind(stream);
                    fseek(stream,save_pos,SEEK_SET);
               }
           }


See Also: fseek() ftell()

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