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