From afa7fe3d51ae3051c74a04c59c93af3396483314 Mon Sep 17 00:00:00 2001 From: Deinerovych Date: Thu, 26 Sep 2024 23:21:24 +0200 Subject: [PATCH] 3 --- cv1/program.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/cv1/program.c b/cv1/program.c index 68dc028..254af3e 100644 --- a/cv1/program.c +++ b/cv1/program.c @@ -35,3 +35,37 @@ int contains_substring(char *food_name, char *ingredient) { } return 0; } + +int main() { + char ingredient[100]; + char food_name[100]; + char price[20]; + int count = 0; + + printf("Zadaj hladanu surovinu: "); + scanf("%s", ingredient); + + printf("Zadaj jedalny listok:\n"); + while (fgets(food_name, sizeof(food_name), stdin)) { + if (food_name[strlen(food_name) - 1] == '\n') { + food_name[strlen(food_name) - 1] = '\0'; + } + if (!fgets(price, sizeof(price), stdin)) { + break; + } + if (price[strlen(price) - 1] == '\n') { + price[strlen(price) - 1] = '\0'; + } + + if (contains_substring(food_name, ingredient)) { + printf("%s\n%s\n", food_name, price); + } + + count++; + } + + printf("Nacitanych %d poloziek.\n", count); + + return 0; +} +