This commit is contained in:
Deinerovych 2024-09-26 23:24:26 +02:00
parent afa7fe3d51
commit 955d347cc6

View File

@ -38,24 +38,23 @@ int contains_substring(char *food_name, char *ingredient) {
int main() {
char ingredient[100];
char food_name[100];
char food_name[200];
char price[20];
int count = 0;
printf("Zadaj hladanu surovinu: ");
scanf("%s", ingredient);
printf("Zadaj hladanu surovinu:\n");
if (!fgets(ingredient, sizeof(ingredient), stdin)) {
return 1;
}
ingredient[strcspn(ingredient, "\n")] = '\0';
printf("Zadaj jedalny listok:\n");
while (fgets(food_name, sizeof(food_name), stdin)) {
if (food_name[strlen(food_name) - 1] == '\n') {
food_name[strlen(food_name) - 1] = '\0';
}
food_name[strcspn(food_name, "\n")] = '\0';
if (!fgets(price, sizeof(price), stdin)) {
break;
}
if (price[strlen(price) - 1] == '\n') {
price[strlen(price) - 1] = '\0';
}
price[strcspn(price, "\n")] = '\0';
if (contains_substring(food_name, ingredient)) {
printf("%s\n%s\n", food_name, price);