Initializacia
This commit is contained in:
parent
b944c638ad
commit
d447a22ab1
@ -28,12 +28,7 @@ char hacker_script(char l) {
|
|||||||
|
|
||||||
void transform_to_hacker_script(const char *src, char *dest) {
|
void transform_to_hacker_script(const char *src, char *dest) {
|
||||||
while (*src) {
|
while (*src) {
|
||||||
if (isupper(*src)) {
|
*dest++ = hacker_script(*src++);
|
||||||
*dest++ = tolower(*src);
|
|
||||||
} else {
|
|
||||||
*dest++ = hacker_script(*src);
|
|
||||||
}
|
|
||||||
src++;
|
|
||||||
}
|
}
|
||||||
*dest = '\0';
|
*dest = '\0';
|
||||||
}
|
}
|
||||||
@ -44,7 +39,7 @@ int contains_normalized(const char *name, const char *search) {
|
|||||||
transform_to_hacker_script(name, transformed_name);
|
transform_to_hacker_script(name, transformed_name);
|
||||||
transform_to_hacker_script(search, transformed_search);
|
transform_to_hacker_script(search, transformed_search);
|
||||||
|
|
||||||
return strcasestr(transformed_name, transformed_search) != NULL;
|
return strstr(transformed_name, transformed_search) != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int read_pizza(struct pizza *item) {
|
int read_pizza(struct pizza *item) {
|
||||||
@ -59,12 +54,7 @@ int read_pizza(struct pizza *item) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *endptr;
|
item->price = strtof(line, NULL);
|
||||||
item->price = strtof(line, &endptr);
|
|
||||||
if (endptr == line || *endptr != '\n') {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,10 +67,6 @@ int main() {
|
|||||||
fgets(search, LINESIZE, stdin);
|
fgets(search, LINESIZE, stdin);
|
||||||
search[strcspn(search, "\n")] = '\0';
|
search[strcspn(search, "\n")] = '\0';
|
||||||
|
|
||||||
for (int i = 0; search[i]; i++) {
|
|
||||||
search[i] = tolower(search[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("Zadaj jedalny listok:\n");
|
printf("Zadaj jedalny listok:\n");
|
||||||
while (read_pizza(&menu[count])) {
|
while (read_pizza(&menu[count])) {
|
||||||
count++;
|
count++;
|
||||||
@ -89,9 +75,6 @@ int main() {
|
|||||||
int found_count = 0;
|
int found_count = 0;
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
if (contains_normalized(menu[i].name, search)) {
|
if (contains_normalized(menu[i].name, search)) {
|
||||||
if (found_count == 0) {
|
|
||||||
printf("\nVysledky vyhladavania:\n");
|
|
||||||
}
|
|
||||||
printf("%s\n%.2f\n", menu[i].name, menu[i].price);
|
printf("%s\n%.2f\n", menu[i].name, menu[i].price);
|
||||||
found_count++;
|
found_count++;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user