diff --git a/sk1/compressor.c b/sk1/compressor.c index f79f191..622fef4 100644 --- a/sk1/compressor.c +++ b/sk1/compressor.c @@ -172,7 +172,13 @@ int RLEcompress(struct Input input, struct Output* output) { return output->length; } -void compress(FILE* infile, FILE* outfile) { +int compress(const char* input_file_name, const char* output_file_name) { + FILE *infile = fopen(input_file_name, "rb"); + if (infile == NULL) { + perror("Error opening input file"); + return -1; + } + fseek(infile, 0, SEEK_END); int insize = ftell(infile) + 1; rewind(infile); @@ -185,6 +191,15 @@ void compress(FILE* infile, FILE* outfile) { assert(!ferror(infile)); } + fclose(infile); + + FILE *outfile = fopen(output_file_name, "wb"); + if (outfile == NULL) { + perror("Error opening output file"); + free(buffer); + return -1; + } + struct Input input = {.buffer = buffer, .size = insize}; struct Output tempOutput; @@ -202,4 +217,7 @@ void compress(FILE* infile, FILE* outfile) { free(buffer); free(tempOutput.result); free(finalOutput.result); -} \ No newline at end of file + + fclose(outfile); + + return 0;