How do you determine the size of a file in C?

前端 未结 14 938
野性不改
野性不改 2020-11-22 03:20

How can I figure out the size of a file, in bytes?

#include 

unsigned int fsize(char* file){
  //what goes here?
}
14条回答
  •  情歌与酒
    2020-11-22 03:42

    You can open the file, go to 0 offset relative from the bottom of the file with

    #define SEEKBOTTOM   2
    
    fseek(handle, 0, SEEKBOTTOM)  
    

    the value returned from fseek is the size of the file.

    I didn't code in C for a long time, but I think it should work.

提交回复
热议问题