Syntax
#include <stdio.h> void rewind(FILE *stream);Description
rewind repositions the file pointer associated with stream to the beginning of the file. A call to rewind is the same as:
(void)fseek(stream, 0L, SEEK_SET);except that rewind also clears the error indicator for the stream. Returns
There is no return value.
This example first opens a file myfile.dat for input and output. It writes integers to the file, uses rewind to reposition the file pointer to the beginning of the file, and then reads the data back in.
#include <stdio.h> FILE *stream; int data1,data2,data3,data4; int main(void) { data1 = 1; data2 = -37; /* Place data in the file */ stream = fopen("myfile.dat", "w+"); fprintf(stream, "%d %d\n", data1, data2); /* Now read the data file */ rewind(stream); fscanf(stream, "%d", &data3); fscanf(stream, "%d", &data4); printf("The values read back in are: %d and %d\n", data3, data4); return 0; /**************************************************************************** The output should be: The values read back in are: 1 and -37 ****************************************************************************/ }Related Information