I'm writing a Huffman algorithm and when I write my file header, I store the length of my file because there will be some spare bits and I need to know where to stop.
This happens instead when I write the length of my file: It writes 8 bytes, but when I read, it reads only 6.
long totChar;
long size;
fprintf(outfile, "%ld", totChar);
fscanf(cmpfile, "%ld", &size);
I'm sure that works because if I add for example:
fgetc(cmpfile); \\compressed file
fgetc(cmpfile);
and then I start reading, the decompression is successful.