Mega Code Archive

 
Categories / C / Code Snippets
 

Moves the file position pointer back to the start

//Header file: #include <stdio.h> //Declaration: void rewind(FILE *stream); #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { FILE *filep; if((filep=fopen("test", "r"))==NULL) { printf("Cannot open file.\n"); exit(1); } while(!feof(filep)){ putchar(getc(filep)); } rewind(filep); while(!feof(filep)){ putchar(getc(filep)); } fclose(filep); }