rewind() Reposition File Pointer to Beginning of Stream
#include <stdio.h>
void rewind(stream);
FILE *stream; Pointer to file structure
rewind() repositions the file pointer associated with 'stream' to the
beginning of the file. rewind() is equivalent to:
fseek(stream,0L,SEEK_SET)
except that rewind() clears the end-of-file and error indicators, and
fseek() does not.
Returns: rewind() does not return a value. (fseek() returns a
value that 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);
}
}
Seealso:
This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster