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);