From 831b080f14bdb7ef30ce23711048f3e0ca852240 Mon Sep 17 00:00:00 2001 From: Kozar Date: Wed, 2 Oct 2024 12:28:51 +0000 Subject: [PATCH] Initializacia --- cv1/program.c | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/cv1/program.c b/cv1/program.c index 556d861..f740b98 100644 --- a/cv1/program.c +++ b/cv1/program.c @@ -6,13 +6,11 @@ #define LINESIZE 100 #define MENU_SiZE 100 -// Štruktúra pre položku jedálneho lístka struct pizza{ char name[LINESIZE]; float price; } -// Prepisovací algoritmus pre "Hack3r scr1pt" char hacker_script(char l){ switch(tolower(char l)){ case 'o': return '0'; @@ -28,7 +26,6 @@ char hacker_script(char l){ } } -// Function to transform a string into "Hack3r scr1pt" void transform_to_hacker_script(const char *src, char *dest) { while (*src) { *dest++ = hacker_script(*src++); @@ -36,38 +33,30 @@ void transform_to_hacker_script(const char *src, char *dest) { *dest = '\0'; } -// Function to search for a normalized string in the name int contains_normalized(const char *name, const char *search) { char transformed_name[LINESIZE], transformed_search[LINESIZE]; - - // Transform both strings + transform_to_hacker_script(name, transformed_name); transform_to_hacker_script(search, transformed_search); - // Search for the string in the name return strstr(transformed_name, transformed_search) != NULL; } -// Function to read a single menu item int read_pizza(struct pizza *item) { char line[LINESIZE]; - // Read the name if (!fgets(item->name, LINESIZE, stdin)) { - return 0; // End of input + return 0; } - // Remove newline character item->name[strcspn(item->name, "\n")] = '\0'; - // Read the price if (!fgets(line, LINESIZE, stdin)) { - return 0; // Failed to read price + return 0; } - // Convert string to float item->price = strtof(line, NULL); - return 1; // Successfully read + return 1; } int main() { @@ -75,21 +64,18 @@ int main() { char search[LINESIZE]; int count = 0; - // Read the search string printf("Zadaj hladanu surovinu:\n"); fgets(search, LINESIZE, stdin); - search[strcspn(search, "\n")] = '\0'; // Remove newline + search[strcspn(search, "\n")] = '\0'; printf("Zadaj jedalny listok:\n"); - // Read the menu items while (read_pizza(&menu[count])) { count++; } printf("\nVysledky vyhladavania:\n"); - // Search and print items that match the search string int found_count = 0; for (int i = 0; i < count; i++) { if (contains_normalized(menu[i].name, search)) { @@ -97,8 +83,7 @@ int main() { found_count++; } } - - // Print the total number of loaded items + printf("Nacitanych %d poloziek.\n", count);s return 0;