Name
rewind
Synopsis
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.
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
Get C in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.