After opening the file, use the fseek () function to move the file position pointer to the end of the file, using Ftell () to get the position pointer from the file header bytes, the number of bytes is the length of the file. However, this is also subject to the following restrictions: The return value of the Ftell () function is long, under Windows (either 32-bit or 64-bit), the long variable has a length of 4 bytes, so that the file length that is normally obtained must be less than 2GB.
Microsoft has provided functions _fseeki64 () and _ftelli64 () in stdio.h in the development tools for Visual Studio 2005 and later versions. The variable that represents the offset of the file pointer in the _fseeki64 () function is the __int64 type, and the return value of _ftelli64 () is also the __int64 type, so you can use these two functions to get the length of a large file (more than 2GB).
Note that the C compiler in Linux and Unix does not provide the _fseeki64 () and _ftelli64 () functions, but the Fseeko () and Ftello () functions are provided in stdio.h, and the Fseeko () function represents the change in the offset of the file pointer The amount is the off_t type, the return value of Ftello () is also off_t type, the length of the off_t type may be 32-bit or 64-bit, using a macro definition #define _FILE_OFFSET_BITS 64 can set off_t to 64.
Here is an example of an implementation that uses C to get the length of a file (which may be greater than 2GB), which can be used on both Windows and Linux platforms (not tested on Unix), including three files:
Http://itlab.idcquan.com/c/skill/943552.html
Get the length of any file in C (may be greater than 2GB) #define _FILE_OFFSET_BITS 64