usaa23/cv1/program.c
2023-10-01 14:36:23 +02:00

72 lines
1.9 KiB
C

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define MAX_ITEMS 100
#define MAX_NAME_LENGTH 100
struct menu {
char name[MAX_NAME_LENGTH];
float price;
};
void transform(char *str) {
for (int i = 0; str[i]; i++) {
switch (str[i]) {
case '0': str[i] = 'o'; break;
case '1': str[i] = 'i'; break;
case '2': str[i] = 'z'; break;
case '3': str[i] = 'e'; break;
case '4': str[i] = 'a'; break;
case '5': str[i] = 's'; break;
case '6': str[i] = 'b'; break;
case '7': str[i] = 't'; break;
case '8': str[i] = 'b'; break;
case '9': str[i] = 'q'; break;
default: break;
}
}
}
int main() {
char searchStr[MAX_NAME_LENGTH];
printf("Zadaj hladanu surovinu:\n");
if (fgets(searchStr, sizeof(searchStr), stdin) == NULL) {
return 1;
}
searchStr[strcspn(searchStr, "\n")] = '\0'; // Odstrániť znak nového riadku
struct menu menu[MAX_ITEMS];
int itemCount = 0;
printf("Zadaj jedalny listok:\n");
while (itemCount < MAX_ITEMS) {
char pizza_name[MAX_NAME_LENGTH];
if (fgets(pizza_name, sizeof(pizza_name), stdin) == NULL) {
break; // Koniec vstupu
}
pizza_name[strcspn(pizza_name, "\n")] = '\0'; // Odstrániť znak nového riadku
// Transformácia názvu jedla
transform(pizza_name);
// Načítanie ceny jedla
float itemPrice;
if (scanf("%f", &itemPrice) != 1) {
break; // Chybný vstup
}
getchar(); // Načítať znak nového riadku
// Skontrolujte, či názov obsahuje vyhľadávací reťazec
if (strstr(pizza_name, searchStr) != NULL) {
printf("%s\n", pizza_name);
printf("%.2f\n", itemPrice);
}
itemCount++;
}
printf("Nacitanych %d poloziek.\n", itemCount);
return 0;
}