From 4eaf1ab6fbc4d2c1693dca98af2cf60293aaa0df Mon Sep 17 00:00:00 2001 From: mr314ot Date: Thu, 9 Oct 2025 19:05:01 +0200 Subject: [PATCH] du2 - 7 --- du2/program.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/du2/program.c b/du2/program.c index 6456430..66c08d3 100644 --- a/du2/program.c +++ b/du2/program.c @@ -2,7 +2,7 @@ #include #include -#define LINESIZE 200 +#define LINESIZE 256 #define MAXITEMS 100 // struktura pre polozku jed. listka @@ -17,7 +17,7 @@ int read_pizza(struct pizza *item) { char line2[LINESIZE]; //nazov - if (fgets(line1, sizeof(line1), stdin) == NULL) { + if (!fgets(line1, sizeof(line1), stdin)) { return 0; } line1[strcspn(line1, "\n")] = '\0'; @@ -26,7 +26,7 @@ int read_pizza(struct pizza *item) { } //cena - if (fgets(line2, sizeof(line2), stdin) == NULL) { + if (!fgets(line2, sizeof(line2), stdin)) { return 0; } line2[strcspn(line2, "\n")] = '\0'; @@ -36,7 +36,8 @@ int read_pizza(struct pizza *item) { return 0; } - strcpy(item->name, line1); + strcpy(item->name, line1, LINESIZE - 1); + item->name[LINESIZE - 1] = '\0'; item->price = value; return 1; } @@ -73,7 +74,7 @@ int main() { } //ukoncit ak ziadne polozky - if (count == 0) { + if (count <= 0) { return 0; }