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;