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

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

    Here's a simple and clean function that returns the file size.

    long get_file_size(char *path)
    {
        FILE *fp;
        long size = -1;
        /* Open file for reading */
        fp = fopen(path, "r");
        fseek(fp, 0, SEEK_END);
        size = ftell(fp); 
        fp.close();
        return 
    }
    

提交回复
热议问题