You need to call ftell after fseek . Try:
long fileSize(FILE *fp){ long start; fflush(fp); rewind(fp); start = ftell(fp); fseek(fp, 0L, SEEK_END); return ftell(fp); }
There is no need to make a difference, so your first ftell useless and you can get rid of it. I would use:
long filezise(FILE *fp) { fseek(fp,OL,SEEK_END);
Also, make sure you open the file in binary mode.
source share