Hello as subject says i am trying to make some simple binary file compressor (for now). I started with basics. This code opens file in binary mode reads byte by byte and input bytes writes to output "compressed" file. If byte == 0x00 counts number of 0x00's and writes 0x00 and number of 0x00's.
#include
#include
int main()
{
int i, duzina, stanje=0, brojac=0;
unsigned char chr;
FILE* ulaz = fopen("../testapp/testapp", "rb");
FILE* izlaz = fopen("../testapp/testapp.zip", "wb");
if(ulaz == NULL)
{
printf("Problem with file!\\n");
exit(1);
}
if(izlaz == NULL)
{
printf("Problem with output file!\\n");
exit(1);
}
fseek(ulaz, 0, SEEK\_END);
duzina = ftell(ulaz);
fseek(ulaz, 0, SEEK\_SET);
for(i=0; i
To "decompress" file i use this code which as input have "compressed" file and read byte by byte if byte == 0x00 reads integer and write N times 0x00 (N value = readed integer)
#include
#include
int main()
{
int i,j, duzina, brojac=0;
unsigned char chr;
FILE\* ulaz = fopen("../testapp/testapp.zip", "rb");
FILE\* izlaz = fopen("../testapp/testapp1", "wb");
if(ulaz == NULL)
{
printf("Problem with file!\\n");
exit(1);
}
if(izlaz == NULL)
{
printf("Problem with output file!\\n");
exit(1);
}
fseek(ulaz, 0, SEEK\_END);
duzina = ftell(ulaz);
fseek(ulaz, 0, SEEK\_SET);
for(i=0; i
So my problem is that when "decompressing" is finshed some bytes are missing (program works correct).
Byte comparing:
[stone@hero testapp]$ diff testapp1.hex testapp.hex
443,444c443,444
< 0001c00 0001
< 0001c01
0001c00 0001 0000 0000 0000 0000 0000 0000 0000
0001c10
[stone@hero testapp]