December 2005
Beginner to intermediate
618 pages
20h 19m
English
rewind
Resets a file’s access position to the beginning of the file
#include <stdio.h> voidrewind( 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.
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 );
}Read now
Unlock full access