In C programming the <stdio.h> rewind function set the file indicator to the beginning of the file.The declaration of the function is given below.
|void rewind(FILE *stream);|
stream -The pointer to the file whose indicator is to be set to the beginning of the file.
Calling ‘rewind’ clears the EOF and error flags or error indicator for the stream.The call ‘rewind’ is also same as,
(void)fseek(stream, 0L, SEEK_SET)
but note the above fssel call does not clear the error indicator for the stream.
int val , count ;
if (fp != NULL)
while ( (val=fgetc(fp)) != EOF) //read text.txt file
if (count == 10)
rewind( fp ); /*clears the current file indicator and set the indicator to the beginning of the file */
printf(“File cannot be opened”);
//Read the file from the beginning
while( (val = fgetc(fp)) !=EOF )
fclose( fp );
If you run the program you will see that the first 10 characters is read and then the file is read from the beginning again.