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

You've just finished reading the article "The rewind () function in C" edited by the TipsMake team. You can save the-rewind-function-in-c.pdf to your computer here to read later or print it out. We hope this article has provided you with many useful tech tips and tricks. You can search for similar articles on tips and guides. Thank you for reading and for following us regularly.

« PREV Function setbuf () in C
NEXT » Rename () function in C