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

前端 未结 14 956
野性不改
野性不改 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:43

    If you're fine with using the std c library:

    #include 
    off_t fsize(char *file) {
        struct stat filestat;
        if (stat(file, &filestat) == 0) {
            return filestat.st_size;
        }
        return 0;
    }
    

提交回复
热议问题