110 lines
2.1 KiB
C
110 lines
2.1 KiB
C
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
|
|
|
|
//#define LINESIZE 100
|
|
|
|
struct Menu{
|
|
char name[100];
|
|
float price;
|
|
};
|
|
|
|
int lower(char c) {
|
|
return (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9');
|
|
}
|
|
|
|
char transform(char c) {
|
|
switch (c) {
|
|
case '0': return 'o';
|
|
case '1': return 'i';
|
|
case '2': return 'z';
|
|
case '3': return 'e';
|
|
case '4': return 'a';
|
|
case '5': return 's';
|
|
case '6': return 'b';
|
|
case '7': return 't';
|
|
case '8': return 'b';
|
|
case '9': return 'q';
|
|
default: return c;
|
|
}
|
|
}
|
|
|
|
int compare(const char *str1, const char *str2) {
|
|
int i = 0, j = 0;
|
|
while (str1[i] && str2[j]) {
|
|
char c1 = transform(str1[i]);
|
|
char c2 = transform(str2[j]);
|
|
|
|
if (str1[i] >= 'A' && str1[i] <= 'Z') {
|
|
str1[i] += 'a' - 'A';
|
|
}
|
|
if (str2[i]>= 'A' && str2[i] <= 'Z') {
|
|
str2[i] += 'a' - 'A';
|
|
}
|
|
|
|
if (c1 != c2) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
i++;
|
|
j++;
|
|
}
|
|
return str1[i] == '\0' && str2[j] == '\0'; // Strings are equal
|
|
}
|
|
|
|
int main() {
|
|
char searchStr[100];
|
|
printf("Zadaj hladanu surovinu: ");
|
|
if (fgets(searchStr, sizeof(searchStr), stdin) == NULL) {
|
|
printf("Chyba pri citani vstupu.\n");
|
|
return 1;
|
|
}
|
|
|
|
size_t len = strlen(searchStr);
|
|
if (len > 0 && searchStr[len - 1] == '\n') {
|
|
searchStr[len - 1] = '\0';
|
|
}
|
|
|
|
struct MenuItem menu[100];
|
|
int menuSize = 0;
|
|
|
|
printf("Zadaj jedalny listok:\n");
|
|
|
|
while (menuSize < 100) {
|
|
if (fgets(menu[menuSize].name, sizeof(menu[menuSize].name), stdin) == NULL) {
|
|
break;
|
|
}
|
|
if (sscanf(menu[menuSize].name, "%f", &menu[menuSize].price) != 1) {
|
|
printf("Chyba pri citani ceny.\n");
|
|
return 1;
|
|
}
|
|
menuSize++;
|
|
}
|
|
|
|
printf("\nNájdené položky:\n");
|
|
int foundItems = 0;
|
|
for (int i = 0; i < menuSize; i++) {
|
|
if (strstr(menu[i].name, searchStr) || compareStrings(menu[i].name, searchStr)) {
|
|
printf("%s\n%.2f\n", menu[i].name, menu[i].price);
|
|
foundItems++;
|
|
}
|
|
}
|
|
|
|
printf("\nNacitanych %d poloziek.\n", menuSize);
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|