Use C rewind function to move file pointer position
Syntax
C rewind function has the following syntax.
void rewind(FILE *stream);
Header
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);
}