From 19ef0dec3958140a7f801a5e4364a310fd28b4d3 Mon Sep 17 00:00:00 2001 From: mr314ot Date: Thu, 9 Oct 2025 19:13:54 +0200 Subject: [PATCH] du2 - 9 --- du2/program.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/du2/program.c b/du2/program.c index a244fb4..fa9aafb 100644 --- a/du2/program.c +++ b/du2/program.c @@ -31,14 +31,12 @@ int read_pizza(struct pizza *item) { } line2[strcspn(line2, "\n")] = '\0'; - float value; if (sscanf(line2, "%f", &value) != 1) { return 0; } strncpy(item->name, line1, LINESIZE - 1); item->name[LINESIZE - 1] = '\0'; - item->price = value; return 1; } @@ -68,14 +66,13 @@ int main() { struct pizza list[MAXITEMS]; int count = 0; - //nacitanie listka - while (count < MAXITEMS && read_pizza(&list[count])){ - count++; - } - - //ukoncit ak ziadne polozky - if (count <= 0) { - return 0; + //citanie listka + while (count < MAXITEMS){ + struct pizza tmp; + if (!read_pizza(&tmp)){ + break; + } + list[count++] = tmp; } //triedenie @@ -84,7 +81,7 @@ int main() { //vypis listka for (int i = 0; i < count; i++){ printf("%s\n", list[i].name); - printf("%s\n", list[i].price); + printf("%.6f\n", list[i].price); } return 0;