• Welcome to Web Hosting Community Forum for Webmasters - Web hosting Forum.
 

What will the function rewind() do ?

Started by kavitajain9782, April 20, 2019, 12:33:53 PM

kavitajain9782

Hello Dear,

              Please Tell Me What will the function rewind() do ?

ServersBase

The C library function void rewind(FILE *stream) sets the file position to the beginning of the file of the given stream.
Anika Bhardwaj -ServersBase.Com
100% Uptime Guarantee

Zolgains

Quote from: kavitajain9782 on April 20, 2019, 12:33:53 PM
Hello Dear,

              Please Tell Me What will the function rewind() do ?

If you are talking about the C library function void rewind(FILE *stream), it sets the file position to the beginning of the file of the given stream.

Amarjee2

If you're referring to the C library method void rewind, it reset the file position to the beginning of the specified stream's file.

Akshay_M

The function `rewind()` is a standard library function in C programming language that is used to reset the file position indicator to the beginning of a file. It is typically used with file streams opened using functions like `fopen()`.

The syntax of `rewind()` is:
```c
void rewind(FILE *stream);
```

The `rewind()` function takes a pointer to a `FILE` object as an argument. It resets the position indicator of the associated file stream to the beginning. It clears any error or end-of-file indicators that might have been set.

Here's an example usage of `rewind()`:
```c
#include <stdio.h>

int main() {
    FILE *file = fopen("example.txt", "r");
    if (file == NULL) {
        printf("Failed to open the file.\n");
        return 1;
    }

    // Read some data from the file

    rewind(file);  // Reset the file position to the beginning

    // Read from the beginning of the file again

    fclose(file);
    return 0;
}
```

In the above example, `rewind(file)` is used to reset the file position indicator back to the beginning of the file, allowing you to read from the start again.