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

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

    I have a function that works well with only stdio.h. I like it a lot and it works very well and is pretty concise:

    size_t fsize(FILE *File) {
        size_t FSZ;
        fseek(File, 0, 2);
        FSZ = ftell(File);
        rewind(File);
        return FSZ;
    }
    

提交回复
热议问题