program.c
This commit is contained in:
parent
070aa818cb
commit
319cd77a2b
@ -0,0 +1,93 @@
|
|||||||
|
#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');
|
||||||
|
}
|
||||||
|
|
||||||
|
int compare(const char *str1, const char *str2) {
|
||||||
|
int i = 0, j = 0;
|
||||||
|
while (str1[i] && str2[j]) {
|
||||||
|
char c1 = str1[i];
|
||||||
|
char c2 = str2[j];
|
||||||
|
|
||||||
|
if (c1 >= 'A' && c1 <= 'Z') {
|
||||||
|
c1 += 'a' - 'A';
|
||||||
|
}
|
||||||
|
if (c2 >= 'A' && c2 <= 'Z') {
|
||||||
|
c2 += 'a' - 'A';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c1 != c2) {
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
return str1[i] == '\0' && str2[j] == '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user