Format
#include <stdio.h> void rewind(FILE *stream);
Language Level: ANSI, POSIX, XPG4
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.
Return Value
There is no return value.
Example
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>
#define FILENAME "myfile.dat"
FILE *stream;
int data1, data2, data3, data4;
int main(void)
{
data1 = 1; data2 = -37;
/* Place data in the file */
stream = fopen("FILENAME", "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 *****************************************************/ }
![]()
fgetpos -- Get File Position
fseek -- Reposition File Position
fsetpos -- Set File Position
ftell -- Get Current Position
lseek -- Move File Pointer
_tell -- Get Pointer Position
<stdio.h>