From: Franz Bachler on
Hello all,

I would like to get a working C-Code-Example which compress a file with the
huffman algorythm.

huffman inputfile.txt outputfile.txt

Greetings,
Franz

--
Franz Bachler
A-3250 Wieselburg
E-Mail: fraba (at) gmx.at
Homepage: http://members.aon.at/fraba
oder http://home.pages.at/fraba



From: Franz Bachler on
> I would like to get a working C-Code-Example which compress a file with
> the huffman algorythm.
>
> huffman inputfile.txt outputfile.txt

http://www.codeproject.com/KB/files/huffman.aspx

This works fine and is fast. But if you recompress the compressed file again
you save approx. 7 % space.


From: Franz Bachler on
Hello again,

>> I would like to get a working C-Code-Example which compress a file with
>> the huffman algorythm.
>> huffman inputfile.txt outputfile.txt
>
> http://www.codeproject.com/KB/files/huffman.aspx
>
> This works fine and is fast.

But if you compile with the compiler e.g. Borland C++ 5.5.1 and with
Microsoft Visual Studio or DJGPP then you can't decode a compressed file
encoded with the program from a different compiler.

The reason is qsort(); the different compilers produces different results.

replace qsort with your own (e.g. bubble) sort routine:

qsort((void *)temptree, 256, sizeof(hufftree), &compare);

bubblesort(temptree, 256);


void bubblesort(hufftree t[], int len)

{
int i,j;
hufftree temp;

for (i=0; i<len-1; i++)
{
for (j=0; j<len-i-1; j++)
{
if (t[j].freq<t[j+1].freq)
{
temp = t[j];
t[j] = t[j+1];
t[j+1] = temp;
}
}
}
}

Greetings,
Franz