File Compressor in C
- 26 Devlogs
- 68 Total hours
Writing C file compressor! Two step install guide in the README, enjoy!
Writing C file compressor! Two step install guide in the README, enjoy!
I CAN’T MAKE WEBSITES, I CAN’T STAND JAVASCRIPT. I tried to use WebAssembly, but it’s not widely used, so it’s really hard to work with.
Well, use it with the CLI like a super nerd
Don’t worry, everything is documented in the README. CLI » JAVASCRIPT
I added the .huff extension since it will help me recognize files compressed by my compressor. The format used is .extension.huff (example: image.jpg.huff).
I compiled the code to web assembly so it can run directly on the user’s PC and not on servers.
I’m creating a simple website that just does the j*b (still woking on it, this is just the core). The website will not communicate with other APIs or services, thanks to web assembly. I hate JavaScript.
So i had this error for the past 4 days and i coudn’t fix it so i even take a step back for 2 days but still coudn’t find it, the problem was that i had to wait 5 min for every try i did.
I used claude so he run test on faster machines, and i got the errors i have to fix. (He wanted to script it himself, i obviously said no).
I successfully compressed and decompressed a file other than text files, I used binary to write the files so it supports all the file types now!
So the compressed file were written in text and decompressed with text wich limited the compression for only text files.
I wrote the compressed file and decompressed in binary.
(small part of the code i changed)
There was an issue with compressor.c while doing it with other files than png. I’m still working on decompressor.c it can’t decode normally a file other than png. Text files still works.
Its so hot in europe, I can’t work normally, the temperatures will go down monday hopefully.
so the main bug was that the two arrays which contained the frequencies of each letter were reversed so the huffman tree was not the same and the codes too weren’t the same.
so in decompressor.c i just reversed the codes. this is not a permanent fix will investigate further into compressor.c to see why its reversed!
i had an issue where i was putting the new node in first in the link list so i fix it, drawing it on a sketch really helped.
So i transfer it into an array since its easier to use it and i coudn’t built it before since an array is a fixed size, thats why I used a linked list to first get the values and the length.
I just imported function i already programmed in compressor.c.
image from wikipedia
its a real question why only I ? I used f it was so cool.
Use other letters for your loops. I’m onto something guys, it’s the next big thing.
P.S: I’m going to take a break from coding in C since its pretty anoying and im not really doing anything while working maybe this challenge is really too hard for me.
I’m maybe going to start another project then see.
Finnaly finished compressor.c after 7 hours on it!
Well i used AI… Yes I’m not proud but hey its finished!
I was really tired and I just vibe coded it but now no more AI for decompressor.c !
Yes i didn’t blindly ask AI do give answers i asked to help debug the code!
Probably sleep, I’m so tired.
Finally finished coding everything but the tree.
so for relearning, i authorized myself to use AI but only to debug, now i can finally not use it (since i relearned C)
I ran into several problems:
For context i was building the compressor and i had segmentation problems
A segmentation problem is when you try and access memory your don’t have access.
I used AI to debug my code, I didnt directly asked for the awnsers, i asked it to help me without giving out awnsers. AI was very useful since i mad alot of small mistakes since i didnt program in C for a long time.
Huffman Coding is a lossless compression algorithm.
Example text: ffffcdabdfdeeebcc
First, count how often each character appears:
f:4 c:3 d:3 e:3 b:2 a:1
Then repeatedly merge the least frequent characters into a binary tree until one final tree remains.
Each character gets a binary code:
0
1
More frequent characters receive shorter codes, reducing the total file size.
A key rule: no code can start with another code.
If f = 1, then 100 cannot be another character, so decoding stays unambiguous.
Time complexity: O(n log n)
Image: GeeksforGeeks
Video: Computerphile – Huffman Coding