From 48b5aeb74741c38211f783cf0633a0ac262b2dfd Mon Sep 17 00:00:00 2001 From: Yevhen Kozirovskyi Date: Tue, 1 Oct 2024 22:03:29 +0000 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20cv1/program.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cv1/program.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/cv1/program.c b/cv1/program.c index 92918f2..aa9e0b0 100644 --- a/cv1/program.c +++ b/cv1/program.c @@ -29,22 +29,28 @@ int main() { int count = 0; printf("Zadaj hladanu surovinu: "); - fgets(ingredient, MAX_NAME_LEN, stdin); + if (fgets(ingredient, MAX_NAME_LEN, stdin) == NULL) { + fprintf(stderr, "Ошибка чтения ингредиента.\n"); + return 1; // Обработка ошибки + } ingredient[strcspn(ingredient, "\n")] = '\0'; printf("Zadaj jedalny listok:\n"); while (1) { char name[MAX_NAME_LEN], price[MAX_NAME_LEN]; - fgets(name, MAX_NAME_LEN, stdin); + if (fgets(name, MAX_NAME_LEN, stdin) == NULL) { + return 0; // Обработка ошибки + } name[strcspn(name, "\n")] = '\0'; if (strlen(name) == 0) { break; } - // Ввод цены - fgets(price, MAX_NAME_LEN, stdin); + if (fgets(price, MAX_NAME_LEN, stdin) == NULL) { + return 0; // Обработка ошибки + } price[strcspn(price, "\n")] = '\0'; // Использование strncpy для безопасности