Finding the size of a file
For the first function you can address the OS to find out for you:

unsigned long long fsizeof_full(FILE *fp) {
    struct stat size;
    fstat(fileno(fp), &amp;size);
    return size.st_size;
}


You'll need to include the following headers for it to work.

#include &lt;sys/types.h&gt;
#include &lt;sys/stat.h&gt;


Or you can simply seek to the end of the file (with fseek(fp, 0, SEEK_END)) and use ftell

Besides that files nowadays can easily exceed 4 gigabytes which will overflow the int, both posix and windows have (differently named) variants on ftell that returns a 64 bit number.