ftell()

Declaration

long ftell(FILE* qpStream);

Description:

This function returns the position of the internal file pointer for the stream "qpStream." If the function is not successful, it returns EOF.

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;
    }

    // Set the file pointer to two from the end
    int iRet = fseek(qpFile, 2, SEEK_END);
    // Find the position of the pointer in the file.
    long lPos = ftell(qpFile);
    if (lPos != EOF) {
        printf("File pointer is at %i\n", lPos);
    }

    fclose(qpFile);

    return 0;
}

Input File:

ftell() Input File

Output:

ftell() Output