From ed1451ea4974a62bea00eced751b7d33980de1e2 Mon Sep 17 00:00:00 2001 From: Yurii Chechur Date: Sun, 29 Sep 2024 18:51:56 +0000 Subject: [PATCH] Update program.c --- program.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/program.c b/program.c index e69de29..0e85f3f 100644 --- a/program.c +++ b/program.c @@ -0,0 +1,77 @@ +#include +#include + + +void replace(char* DishName); + +struct MenuItem { + char category[50]; + char dish[50]; + float price; +}; + +char answer1[100]; + +int main(void) { + + + struct MenuItem menu[] = { + {"Pizza", "Margarita", 4.4}, + {"Pizza", "Cucumber", 4.4}, + {"Pizza", "Ajika", 4.4}, + {"Pizza", "Paperoni", 4.4} + }; + + + printf("Zadaj hladanu surovinu: "); + fgets(answer1, 100, stdin); + + + if (answer1[strlen(answer1) - 1] == '\n') { + answer1[strlen(answer1) - 1] = '\0'; + } + + int MenuSize = sizeof(menu) / sizeof(menu[0]); + int found = 0; + + + for (size_t i = 0; i < MenuSize; i++) { + + if (strstr(menu[i].dish, answer1) != NULL) { + found = 1; + + replace(menu[i].dish); + printf("Chcete to to: %s, Cena: %.2f\n", menu[i].dish, menu[i].price); + } + } + + + if (!found) { + printf("Zadana surovina nebola najdena.\n"); + } + + return 0; +} + + +void replace(char* DishName) { + + char original[] = "aAeEiIoOsSzZ"; + + char replacement[] = "443311005522"; + + int l = strlen(DishName); + + + for (int i = 0; i < l; i++) { + + for (int j = 0; j < strlen(original); j++) { + if (DishName[i] == original[j]) { + + DishName[i] = replacement[j]; + break; + } + } + } +} +