User Tools

Site Tools


Programming Reference/Librarys

Question & Answer

Q&A is closed


Table of Contents


    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

C Sourcecode Example

 * rewind example code
#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 */
/* 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;

content of test.txt

Test example file for rewind source code


  output: ./rewind 
  Test example file for rewind source code rewind source code

see also fseek

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
c/stdio.h/rewind.txt · Last modified: 2024/02/16 01:05 (external edit)

Impressum Datenschutz