C Standard Libraries C++

rewind()

Declaration

void rewind(FILE* qpStream);

Description

This function positions the internal file pointer for the stream "qpStream" to the begining of the file. The function clears all error and end-of-file indicators for the stream.

Input File

rewind() Input File

Example

#include <cstdio>

int main()
{
    char* cpFileName = "XoaX.txt";
    // Open an ASCII text file for reading.
    FILE* qpFile = fopen(cpFileName, "r");

    // Check that the file was opened successfully.
    if (!qpFile) {
        printf("Could not open the file %s\n",  cpFileName);
        return 1;
    }
    // Set the file pointer position to 4
    fseek(qpFile, 4, SEEK_SET);
    long lPos = ftell(qpFile);
    printf("File pointer is at %d\n", lPos);

    // Set the file pointer position back to 0
    rewind(qpFile);
    lPos = ftell(qpFile);
    printf("File pointer is at %d\n", lPos);

    fclose(qpFile);

    return 0;
}

Output

rewind() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.