Programming Reference/Librarys
Question & Answer
Q&A is closed
void rewind(FILE *stream);
equal like fseek(stream, 0L, SEEK_SET); clearerr(stream); Resets the read pointer to the beginning of the File and clear the error indicator
/* * rewind example code * http://code-reference.com/c/stdio.h/rewind */ #include <stdio.h> /* including standard library */ //#include <windows.h> /* uncomment this for Windows */ int main (void) { FILE *stream; int c; long seek_position; seek_position = 21; stream=fopen("test.txt", "r" ); if (stream == 0) { perror("cannot open file"); return 0; } while( (c=getc(stream)) != EOF) { putc(c, stdout); } /* Set Position with rewind to the beginning of the file */ rewind(stream); /* SET SEEK CUR to 20 char of the file */ fseek(stream, seek_position, SEEK_CUR ); while( (c=getc(stream)) != EOF) { putc(c, stdout); } return 0; }
output: ./rewind
Test example file for code-reference.com rewind source code
code-reference.com rewind source code
see also fseek