User Tools

Site Tools


c:stdio.h:rewind

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

c:stdio.h:rewind [2013/01/22 22:02]
c:stdio.h:rewind [2024/02/16 01:05] (current)
Line 1: Line 1:
 +{{keywords>wiki library source code example reference}}
 +===== rewind =====
 +
 +<code c>
 +    void rewind(FILE *stream);
 +</code>
 +
 +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 =====
 +<code c>
 +/* 
 + * 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;
 +}
 +</code>
 +
 +
 +=== content of test.txt ===
 +<code c>
 +Test example file for code-reference.com rewind source code
 +</code>
 +
 +==== output ====
 +    output: ./rewind 
 +    Test example file for code-reference.com rewind source code
 +    code-reference.com rewind source code
 +
 +    
 +    
 +see also [[c:stdio.h:fseek|]]
  

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War

Impressum Datenschutz