Update sk1/main.c
This commit is contained in:
parent
e0381dccd5
commit
e29d9e80b1
81
sk1/main.c
81
sk1/main.c
@ -7,48 +7,57 @@
|
||||
#define BUFSIZE 1024
|
||||
|
||||
void print_help() {
|
||||
printf("Usage:\n");
|
||||
printf(" ./compressor -c1 infile outfile Compress using algorithm 1 (Huffman)\n");
|
||||
printf(" ./compressor -d1 infile outfile Decompress using algorithm 1 (Huffman)\n");
|
||||
printf(" ./compressor -c2 infile outfile Compress using algorithm 2 (RLE)\n");
|
||||
printf(" ./compressor -d2 infile outfile Decompress using algorithm 2 (RLE)\n");
|
||||
printf(" ./compressor -h Show this help message\n");
|
||||
printf("Available Options:\n");
|
||||
printf("1 - Compress using algorithm 1 (Huffman)\n");
|
||||
printf("2 - Decompress using algorithm 1 (Huffman)\n");
|
||||
printf("3 - Compress using algorithm 2 (RLE)\n");
|
||||
printf("4 - Decompress using algorithm 2 (RLE)\n");
|
||||
printf("0 - Exit\n");
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc < 2) {
|
||||
print_help();
|
||||
return 1;
|
||||
}
|
||||
int main() {
|
||||
int choice;
|
||||
char infile[256], outfile[256];
|
||||
|
||||
if (strcmp(argv[1], "-h") == 0) {
|
||||
print_help();
|
||||
return 0;
|
||||
}
|
||||
// Покажемо користувачу доступні варіанти
|
||||
print_help();
|
||||
|
||||
// Ensure correct number of arguments
|
||||
if (argc != 4) {
|
||||
fprintf(stderr, "Error: Invalid number of arguments.\n");
|
||||
print_help();
|
||||
return 1;
|
||||
}
|
||||
while (1) {
|
||||
// Запитуємо користувача про вибір
|
||||
printf("Enter your choice (0 to exit): ");
|
||||
if (scanf("%d", &choice) != 1) {
|
||||
fprintf(stderr, "Invalid input. Exiting.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
const char* mode = argv[1];
|
||||
const char* infile = argv[2];
|
||||
const char* outfile = argv[3];
|
||||
if (choice == 0) {
|
||||
printf("Exiting program.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if (strcmp(mode, "-c1") == 0) {
|
||||
compress_1(infile, outfile);
|
||||
} else if (strcmp(mode, "-d1") == 0) {
|
||||
decompress_1(infile, outfile);
|
||||
} else if (strcmp(mode, "-c2") == 0) {
|
||||
compress_2(infile, outfile);
|
||||
} else if (strcmp(mode, "-d2") == 0) {
|
||||
decompress_2(infile, outfile);
|
||||
} else {
|
||||
fprintf(stderr, "Error: Unknown mode '%s'.\n", mode);
|
||||
print_help();
|
||||
return 1;
|
||||
// Вводимо імена файлів
|
||||
printf("Enter input file name: ");
|
||||
scanf("%s", infile);
|
||||
printf("Enter output file name: ");
|
||||
scanf("%s", outfile);
|
||||
|
||||
switch (choice) {
|
||||
case 1:
|
||||
compress_1(infile, outfile);
|
||||
break;
|
||||
case 2:
|
||||
decompress_1(infile, outfile);
|
||||
break;
|
||||
case 3:
|
||||
compress_2(infile, outfile);
|
||||
break;
|
||||
case 4:
|
||||
decompress_2(infile, outfile);
|
||||
break;
|
||||
default:
|
||||
printf("Invalid choice. Please select again.\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user