Previous Page
Next Page

rewind

Resets a file's access position to the beginning of the file

#include <stdio.h>
void rewind ( FILE *fp  );

The rewind( ) function sets the access position of the file associated with the FILE pointer fp to the beginning of the file, and clears the EOF and error flags.

Example

This example prints the contents of a file twice, converting each character to lowercase the first time through, and to uppercase the second time:

FILE *fp; int c;

if (( fp = fopen( argv[1], "r" )) == NULL )
  fprintf( stderr, "Failed to open file %s\n", argv[1] );
else
{
  puts( "Contents of the file in lower case:" );
  while (( c = fgetc( fp )) != EOF )
    putchar( tolower( c ));

  rewind( fp );

  puts( "Same again in upper case:" );
  while (( c = fgetc( fp )) != EOF )
    putchar( toupper( c ));

  fclose( fp );
}

See Also

fseek( ), ftell( ), fgetpos( ), fsetpos( ), clearerr( )


Previous Page
Next Page