User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







c:stdio.h:rewind

Table of Contents

rewind

    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
 * 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;
}

content of test.txt

Test example file for code-reference.com rewind source code

output

  output: ./rewind 
  Test example file for code-reference.com rewind source code
  code-reference.com rewind source code

see also fseek

advertising
c/stdio.h/rewind.txt · Last modified: 2013/01/22 22:02 (external edit)

Impressum