C programming stdio.h function - void rewind(FILE *stream)

www.‮tfigi‬idea.com

In C programming, the rewind() function is defined in the stdio.h header file and is used to reset the file position indicator to the beginning of a file. The function takes one argument, a pointer to a FILE object that represents the file to be rewound:

void rewind(FILE *stream);

The rewind() function does not return a value. It simply sets the file position indicator for the specified file to the beginning of the file.

Here's an example of how to use the rewind() function to reset the file position indicator to the beginning of a file:

#include <stdio.h>

int main() {
    FILE *fp = fopen("example.txt", "r");

    // Read some data from the file

    rewind(fp);  // Rewind the file to the beginning

    // Read some more data from the beginning of the file

    fclose(fp);

    return 0;
}

In the above example, the fopen() function is used to open a file named "example.txt" for reading. Some data is then read from the file, and then the rewind() function is called to reset the file position indicator to the beginning of the file. Finally, some more data is read from the beginning of the file before the file is closed with the fclose() function.