Add 'sk1/main.c'

This commit is contained in:
Anzhelika Nikolaieva 2024-01-29 23:29:42 +00:00
parent 58c4849c0e
commit 925304c272

32
sk1/main.c Normal file
View File

@ -0,0 +1,32 @@
#include "compressor.h"
#include <string.h>
int main(int argc, char* argv[]) {
if (argc != 4 || (argv[1][1] != 'c' && argv[1][1] != 'd')) {
printf("Usage: %s -c input output\n", argv[0]);
printf("Usage: %s -d output input\n", argv[0]);
return 1;
}
FILE* infile = fopen(argv[2], "rb");
FILE* outfile = fopen(argv[3], "wb");
if (infile == NULL || outfile == NULL) {
perror("Error opening files");
return 1;
}
if (strcmp(argv[1], "-c") == 0) {
compress(infile, outfile);
} else if (strcmp(argv[1], "-d") == 0) {
decompress(infile, outfile);
} else {
fprintf(stderr, "Invalid option: %s\n", argv[1]);
return 1;
}
fclose(infile);
fclose(outfile);
return 0;
}