The rewind () function in C

The void rewind function (FILE * stream) in Standard C library sets the file location to the beginning of the file in the given stream.

The void rewind function (FILE * stream) in Standard C library sets the file location to the beginning of the file in the given stream .

Declaring rewind () function in C

Below is the declaration for rewind () function in C:

 void rewind ( FILE * stream ) 

Parameters

stream - This is the pointer to a FILE object that identifies the Stream.

Returns the value

This function does not return any values.

For example

The following C program illustrates the use of rewind () function in C:

 #include int main () { char str [] = "Hoc C co ban va nang cao tai QTM !!!" ; FILE * fp ; int ch ; /* Dau tien chung ta ghi mot so noi dung vao baitapc.txt */ fp = fopen ( "baitapc.txt" , "w" ); fwrite ( str , 1 , sizeof ( str ) , fp ); fclose ( fp ); fp = fopen ( "baitapc.txt" , "r" ); while ( 1 ) { ch = fgetc ( fp ); if ( feof ( fp ) ) { break ; } printf ( "%c" , ch ); } rewind ( fp ); printf ( "n" ); while ( 1 ) { ch = fgetc ( fp ); if ( feof ( fp ) ) { break ; } printf ( "%c" , ch ); } fclose ( fp ); return ( 0 ); } 

Compile and run the above C program to see the results:

According to Tutorialspoint

Previous article: rename () function in C

Next lesson: Function setbuf () in C

4 ★ | 1 Vote