From 21af9602eb1eade76651d5e1119da869be1cfb03 Mon Sep 17 00:00:00 2001 From: Deinerovych Date: Wed, 9 Oct 2024 10:08:03 +0200 Subject: [PATCH] 2 --- cv2/program.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/cv2/program.c b/cv2/program.c index 014c99e..3f585fa 100644 --- a/cv2/program.c +++ b/cv2/program.c @@ -21,15 +21,23 @@ int comparePizzas(const void *a, const void *b) { } int main() { - Pizza menu[] = { - {"Salamovo Fazulova pizza", 7.96}, - {"Sunkova pizza", 5.77}, - {"Bryndzova pizza", 8.67}, - {"Zelerova pizza", 8.86}, - {"Slaninovo Sunkova pizza", 7.55}, - {"Slaninova pizza", 5.16} - }; - int menuSize = sizeof(menu) / sizeof(menu[0]); + Pizza menu[100]; // Максимум 100 пицц + int menuSize = 0; + + while (1) { + Pizza pizza; + if (fgets(pizza.name, sizeof(pizza.name), stdin) == NULL) { + break; + } + // Удаляем символ новой строки, если он есть + pizza.name[strcspn(pizza.name, "\n")] = 0; + + if (scanf("%lf%*c", &pizza.price) != 1) { + break; + } + + menu[menuSize++] = pizza; + } qsort(menu, menuSize, sizeof(Pizza), comparePizzas);