This commit is contained in:
Džubara 2025-01-19 20:40:43 +01:00
parent 1e6fb33624
commit 76c9eef337

View File

@ -120,7 +120,7 @@ int compress_1(const char* input_file_name, const char* output_file_name) {
unsigned char* data = read_file(input_file_name, &size); unsigned char* data = read_file(input_file_name, &size);
if (!data) return -1; if (!data) return -1;
HuffmanNode* root = build_huffman_tree(data, size); HuffmanNode* root = build_huffman_tree(data, size);
if (!root) { if (!root) {
free(data); free(data);
@ -141,7 +141,14 @@ int compress_1(const char* input_file_name, const char* output_file_name) {
return -1; return -1;
} }
fwrite(data, 1, size, output_file);
for (size_t i = 0; i < size; i++) {
fputs(codes[data[i]], output_file);
}
fclose(output_file); fclose(output_file);
printf("Compressing using Huffman coding...\n"); printf("Compressing using Huffman coding...\n");