Use C rewind function to move file pointer position

Syntax

C rewind function has the following syntax.

void rewind(FILE *stream);

C rewind function is from header file stdio.h.

Description

C rewind function moves the file position pointer back to the start.

Example

Use C rewind function to move file pointer.


#include <stdio.h>
#include <stdlib.h>
//from  ww w . jav  a2 s  .c  o m
int main(int argc, char *argv[])
{
  FILE *fp;

  if((fp=fopen("test", "r"))==NULL) {
    printf("Cannot open file.\n");
    exit(1);
  }

  while(!feof(fp)){
      putchar(getc(fp));
  }
  rewind(fp);


  while(!feof(fp)){
      putchar(getc(fp));
  }
  fclose(fp);
}




















Home »
  C Language »
    Function Reference »




assert.h
ctype.h
math.h
setjmp.h
signal.h
stdio.h
stdlib.h
string.h
time.h
wctype.h