From 8a8a3588ccb72c3e28989f5150a095d62e5b234e Mon Sep 17 00:00:00 2001 From: mr314ot Date: Thu, 9 Oct 2025 19:25:35 +0200 Subject: [PATCH] du2 - 11 --- du2/program.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/du2/program.c b/du2/program.c index 50430fc..538460c 100644 --- a/du2/program.c +++ b/du2/program.c @@ -31,13 +31,19 @@ int read_pizza(struct pizza *item) { } line2[strcspn(line2, "\n")] = '\0'; - float value; + float value = 0.0f; if (sscanf(line2, "%f", &value) != 1) { - return 0; + for (int i = 0; line2[i]; i++){ + if (line2[i] == ',') line2[i] = '.'; + } + if (sscanf(line2, "%f", &value) != 1){ + return 0; + } } strncpy(item->name, line1, LINESIZE - 1); item->name[LINESIZE - 1] = '\0'; + item->price = value; return 1; } @@ -64,24 +70,23 @@ void sort_pizzas(struct pizza *list, int count) { } int main() { + setlocale(LC_ALL, "C"); + struct pizza list[MAXITEMS]; int count = 0; //citanie listka while (count < MAXITEMS){ struct pizza tmp; - if (!read_pizza(&tmp)){ - break; - } + if (!read_pizza(&tmp)) break; list[count++] = tmp; } - if (count > 0) { - sort_pizzas(list, count); - for (int i = 0; i < count; i++){ - printf("%s\n", list[i].name); - printf("%.6f\n", list[i].price); - } + sort_pizzas(list, count); + + for (int i = 0; i < count; i++){ + printf("%s\n", list[i].name); + printf("%.6f\n", list[i].price); } return 0;