This commit is contained in:
Deinerovych 2024-10-09 10:08:03 +02:00
parent d4adaf65b0
commit 21af9602eb

View File

@ -21,15 +21,23 @@ int comparePizzas(const void *a, const void *b) {
} }
int main() { int main() {
Pizza menu[] = { Pizza menu[100]; // Максимум 100 пицц
{"Salamovo Fazulova pizza", 7.96}, int menuSize = 0;
{"Sunkova pizza", 5.77},
{"Bryndzova pizza", 8.67}, while (1) {
{"Zelerova pizza", 8.86}, Pizza pizza;
{"Slaninovo Sunkova pizza", 7.55}, if (fgets(pizza.name, sizeof(pizza.name), stdin) == NULL) {
{"Slaninova pizza", 5.16} break;
}; }
int menuSize = sizeof(menu) / sizeof(menu[0]); // Удаляем символ новой строки, если он есть
pizza.name[strcspn(pizza.name, "\n")] = 0;
if (scanf("%lf%*c", &pizza.price) != 1) {
break;
}
menu[menuSize++] = pizza;
}
qsort(menu, menuSize, sizeof(Pizza), comparePizzas); qsort(menu, menuSize, sizeof(Pizza), comparePizzas);