2011年4月14日 星期四

How to get file size in C

We can use two function to achieve it.
Use fseek to set the file pointer at end of file.
Then use ftell get current relative position to beginning of file.
Finally, we should set file pointer back to beginning of file.

The code as below:
fseek(pFile, 0, SEEK_END); // seek to end of file
fileSize = ftell(pFile);               // get current file pointer
fseek(pFile, 0, SEEK_SET);  // seek back to beginning of file

沒有留言:

張貼留言