If you have FILE* other than stdin , you can use:
rewind(fptr);
or
fseek(fptr, 0, SEEK_SET);
to reset pointer to the beginning of the file.
You cannot do this for stdin .
If you need to reset the pointer, pass the file as an argument to the program and use fopen to open the file and read its contents.
int main(int argc, char** argv) { int c; FILE* fptr; if ( argc < 2 ) { fprintf(stderr, "Usage: program filename\n"); return EXIT_FAILURE; } fptr = fopen(argv[1], "r"); if ( fptr == NULL ) { fprintf(stderr, "Unable to open file %s\n", argv[1]); return EXIT_FAILURE; } while((c=fgetc(fptr))!=EOF) {
source share