Standard Library Functions in C

adplus-dvertising
rewind() Function
Previous Home Next

Description

The C library function, The rewind( ) function moves the file position indicator to the start of the specified stream. It also clears the end-of-file and error flags associated with stream.

Declaration

Following is the declaration for rewind() function.

void rewind(FILE *stream)

Parameters

stream - A pointer to a FILE object which identifies a stream.

Return Value

The rewind function does not return anything.

Example

#include <stdio.h>

int main( void )
{
   FILE *stream;
   int data1, data2;

   data1 = 1;
   data2 = -37;

   fopen_s( &stream, "crt_rewind.out", "w+" );
   if( stream != NULL )
   {
      fprintf( stream, "%d %d", data1, data2 );
      printf( "The values written are: %d and %d\n", data1, data2 );
      rewind( stream );
      fscanf_s( stream, "%d %d", &data1, &data2 );
      printf( "The values read are: %d and %d\n", data1, data2 );
      fclose( stream );
   }
}

Output

The values written are: 1 and -37
The values read are: 1 and -37
Previous Home Next