This commit is contained in:
Rens Pastoor
2025-06-12 11:20:08 +02:00
parent 37013ec1fc
commit 1086760c4a
21 changed files with 444 additions and 256 deletions

View File

@@ -1,10 +1,46 @@
#include "encode.h"
// add here includes, if needed
#include <stdbool.h>
#include <stdio.h>
int encode_main(int argc, char* argv[])
{
//add your code here
bool encoding = true;
FILE *input_file = fopen(argv[2], "rb");
if (input_file == NULL) {
fprintf(stderr, "Error opening input file: %s\n", argv[2]);
return 1;
}
FILE *output_file = fopen(argv[3], "wb");
if (output_file == NULL) {
fprintf(stderr, "Error opening output file: %s\n", argv[3]);
fclose(input_file);
return 1;
}
while (encoding)
{
// Read data
unsigned char buffer[512];
size_t bytes_read = fread(buffer, 1, sizeof(buffer), input_file);
if (bytes_read == 0) {
if (feof(input_file)) {
encoding = false; // eof reached
} else {
fprintf(stderr, "Error reading from input file\n");
fclose(input_file);
fclose(output_file);
return 1;
}
}
// Encode data
unsigned char encoded_data_high[sizeof(buffer)];
unsigned char encoded_data_low[sizeof(buffer)];
encode_value(buffer, encoded_data_high, encoded_data_low);
// Write data
fwrite(encoded_data_high, 1, bytes_read, output_file);
fwrite(encoded_data_low, 1, bytes_read, output_file);
}
return 0;
}