C : Get Size of Big File

I want to get size of file in C (this program can handling open big input file >4GB). I use function fseek and ftell to get size of file. But the problem when we use this command is fseek and ftell can not handling open big file input (>4GB). Because return value from command ftell is an integer data type. If we want to get size of file (C program can handling open big file input) we can use function fseeko64 and ftello64. This function exist in header sys/types.h (I use Ubuntu Linux).

I will give an example how to get size of big file (C handling big file input) with useĀ  use function fseeko64 and ftello64. This program use input from stdin and compute size of file from that input file. Save this code as cbigfile.c :

Compile this C get size of big file code with command :

gcc cbigfile.c -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -o cbigfile

This is a sample output when this C program open and get size of big file (12GB).

Thank for reading my post about how to open and get size of big file in C.

Source :
http://www.fedoraforum.org/forum/showthread.php?t=187982

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.