65 lines
1.7 KiB
C
65 lines
1.7 KiB
C
#include <assert.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include "compressor.h"
|
|
|
|
#define BUFSIZE 1024
|
|
|
|
void print_help() {
|
|
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 choice;
|
|
char infile[256], outfile[256];
|
|
|
|
// Покажемо користувачу доступні варіанти
|
|
print_help();
|
|
|
|
while (1) {
|
|
// Запитуємо користувача про вибір
|
|
printf("Enter your choice (0 to exit): ");
|
|
if (scanf("%d", &choice) != 1) {
|
|
fprintf(stderr, "Invalid input. Exiting.\n");
|
|
break;
|
|
}
|
|
|
|
if (choice == 0) {
|
|
printf("Exiting program.\n");
|
|
break;
|
|
}
|
|
|
|
// Вводимо імена файлів
|
|
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;
|
|
}
|