Update sk1/main.c
This commit is contained in:
parent
e29d9e80b1
commit
8b0dbfb120
29
sk1/main.c
29
sk1/main.c
@ -26,8 +26,11 @@ int main() {
|
|||||||
// Запитуємо користувача про вибір
|
// Запитуємо користувача про вибір
|
||||||
printf("Enter your choice (0 to exit): ");
|
printf("Enter your choice (0 to exit): ");
|
||||||
if (scanf("%d", &choice) != 1) {
|
if (scanf("%d", &choice) != 1) {
|
||||||
fprintf(stderr, "Invalid input. Exiting.\n");
|
// Якщо введення не є числом, виводимо повідомлення про помилку
|
||||||
break;
|
fprintf(stderr, "Invalid input. Please enter a valid number (0-4).\n");
|
||||||
|
// Очищаємо буфер введення від непотрібних символів
|
||||||
|
while(getchar() != '\n');
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (choice == 0) {
|
if (choice == 0) {
|
||||||
@ -35,12 +38,34 @@ int main() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (choice < 0 || choice > 4) {
|
||||||
|
// Перевіряємо, чи вибір знаходиться в допустимому діапазоні
|
||||||
|
printf("Invalid choice. Please select a valid option (1-4).\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Вводимо імена файлів
|
// Вводимо імена файлів
|
||||||
printf("Enter input file name: ");
|
printf("Enter input file name: ");
|
||||||
scanf("%s", infile);
|
scanf("%s", infile);
|
||||||
printf("Enter output file name: ");
|
printf("Enter output file name: ");
|
||||||
scanf("%s", outfile);
|
scanf("%s", outfile);
|
||||||
|
|
||||||
|
// Перевіряємо, чи існує вхідний файл, і чи доступний вихідний файл для запису
|
||||||
|
FILE *infile_ptr = fopen(infile, "rb");
|
||||||
|
if (!infile_ptr) {
|
||||||
|
printf("Error: Input file does not exist or cannot be opened.\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
fclose(infile_ptr);
|
||||||
|
|
||||||
|
FILE *outfile_ptr = fopen(outfile, "wb");
|
||||||
|
if (!outfile_ptr) {
|
||||||
|
printf("Error: Output file cannot be created or opened.\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
fclose(outfile_ptr);
|
||||||
|
|
||||||
|
// Виконання обраного алгоритму
|
||||||
switch (choice) {
|
switch (choice) {
|
||||||
case 1:
|
case 1:
|
||||||
compress_1(infile, outfile);
|
compress_1(infile, outfile);
|
||||||
|
Loading…
Reference in New Issue
Block a user