fseeko64() and ftello64() for deal with large files (eg. file dimension)

AuSsIeStOnE 2 Tallied Votes 455 Views Share

fseek() and ftell() work only for files < 2,147,483,647 bytes

fseeko64() and ftello64() from <stdio.h> can deal with files up to 18,446,744,073,709,552,000 bytes

the printf format for unsigned long long val is %I64d

eg. Obtaining the file dimension (this code was tested with GNU GCC compiler (MinGW/Cygwin) from code::blocks)

#include <stdio.h>
#include <conio.h>

int main ()

    FILE * pFile;

    unsigned long long file_dim = 0;
    char file_name[260] = "";


    printf("ENTER [path] file name.ext:\n");

    pFile = fopen (file_name,"rb");

    if (pFile==NULL)
        perror ("Error opening file");
        fseeko64 (pFile, 0, SEEK_END);
        file_dim = ftello64 (pFile);
        fclose (pFile);
        printf ("File:\n%s\ncontains %I64d bytes:\n", file_name, file_dim);

    printf("Press any key to exit");

    return 0;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.