rewind
void  rewind ( FILE * stream );
stdio.h
  cplusplus.com  

Repositions the file pointer to the beginning of a stream.
  Sets the file pointer associated with the stream to the beginning of the file.
  A call to rewind is equivalent to:
fseek ( stream , 0L , SEEK_SET );
except that unlike fseek, using rewind the error indicator is cleared.
  The next operation with the stream after a call to fseek can be either for input or output.
  This function is also useful for clearing the keyboard buffer (normally associated with stdin).

Parameters.

stream
Pointer to an open file.

Return Value.
  none

Portability.
  Defined in ANSI-C.

Example.

/* rewind example */
#include <stdio.h>

main ()
{
  int n;
  FILE * pFile;
  char buffer [27];

  pFile = fopen ("myfile.txt","w+");
  for ( n='A' ; n<='Z' ; n++)
    fputc ( n, pFile);
  rewind (pFile);
  fread (buffer,1,26,pFile);
  fclose (pFile);
  buffer[26]='\0';
  puts (buffer);
  return 0;
}

A file called myfile.txt is created for reading and writing and filled with the alphabet. The file is rewinded, read and its content is stored in a buffer, that then is written to the standard output (screen).
ABCDEFGHIJKLMNOPQRSTUVWXYZ

See also.
  fseek


© The C++ Resources Network, 2000