Description
The C library function void rewind (file *stream) sets the file position to the beginning of the file of the given Stream.
Declaration
Following is the declaration for Rewind () function.
void Rewind(*stream)
Parameters
Return Value
This function does no return any value.
Example
The following example shows the usage of the rewind () function.
#include <stdio.h>IntMain(){ CharStr[] = "This is tutorialspoint.com";FILE*Fp; IntCh; /* First let's write some content in the file */Fp=fopen( "File.txt" , "W" );Fwrite(Str, 1 , sizeof(Str) ,Fp);Fclose(Fp);Fp=fopen( "File.txt" , "R" ); While(1) {Ch=Fgetc(Fp); If(Feof(Fp) ) { Break ; }Printf("%c",Ch); }
Set the file position to the beginning, if it doesn ' t has this function, FP would point NULL, because above while (1) and Break if feof (FP) is true. Rewind(Fp);Printf("\ n"); While(1) {Ch=Fgetc(Fp if ( Feof ( fp) { break ;} Printf ( "%c" , Ch } Fclose (FP return (0 /span>
Let us assume we had a text file file.txt that has the following content−
This is tutorialspoint. COM
Now let us compile and run the above program to produce the following result−
This is Tutorialspoint.comthis is tutorialspoint.com
C Library Function-rewind ()