C Standard Libraries C++

fsetpos()

Declaration

int fsetpos(FILE* qpStream, const fpos_t* kqpPos);

Description

This function sets the position of the internal file pointer for the stream "qpStream" to the location specified by "kqpPos." If the function is successful, it returns 0. Otherwise, it returns a nonzero value and sets the value of errno to the appropriate constant value.

Input File

fsetpos() 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 %s for reading \n",  cpFileName);
        return 1;
    }

    fpos_t qPosition = 5;
    // Set the pointer to position 5 in the file.
    int iRet = fsetpos(qpFile, &qPosition);
    if (iRet == 0) {
        // Read in 'n' at 5 places from the beginning
        int iRead = fgetc(qpFile);
        printf("Read in: %c\n", (char)iRead);
    }
    fclose(qpFile);

    return 0;
}

Output

fsetpos() Output
 

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