![]() |
![]() |
![]() |
Rewind a file stream to the beginning of the file
#include <stdio.h> void rewind( FILE *fp );
libc
The rewind() function rewinds the file stream specified by fp to the beginning of the file. It's equivalent to calling fseek() like this:
fseek( fp, 0L, SEEK_SET );
except that the error indicator for the stream is cleared.
This example shows how a two-pass assembler might be implemented:
#include <stdio.h> #include <stdlib.h> void assemble_pass( FILE *fp, int passno ) { printf( "Pass %d\n", passno ); /* Do more work on the fp */ switch( passno ) { case 1: /* do the first-pass work */ break; case 2: /* do the second-pass work */ break; default: break; } } int main( void ) { FILE *fp; fp = fopen( "program.s", "r" ); if( fp != NULL ) { assemble_pass( fp, 1 ); rewind( fp ); assemble_pass( fp, 2 ); fclose( fp ); return EXIT_SUCCESS; } puts( "Error opening program.s" ); return EXIT_FAILURE; }
Safety: | |
---|---|
Cancellation point | Yes |
Interrupt handler | No |
Signal handler | No |
Thread | Yes |
![]() |
![]() |
![]() |