Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
S

stonemanhero

@stonemanhero
About
Posts
1
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Very simple binary file compressor in C
    S stonemanhero

    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]

    C / C++ / MFC help
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups