From 563a7af4f23aedf2582e0978a0b1134f6b464cc7 Mon Sep 17 00:00:00 2001 From: Bohdana Marchenko Date: Thu, 6 Mar 2025 10:56:22 +0000 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20du2/program.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du2/program.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/du2/program.c b/du2/program.c index f742046..f81804b 100644 --- a/du2/program.c +++ b/du2/program.c @@ -8,11 +8,10 @@ int read_double(double *value, int coef_index) { char line[LINE_SIZE]; if (fgets(line, LINE_SIZE, stdin) == NULL) { - return 0; // Chyba pri čítaní + return 0; } line[strcspn(line, "\r\n")] = 0; - if (strlen(line) == 0) { return 0; } @@ -20,10 +19,9 @@ int read_double(double *value, int coef_index) { char *endptr; *value = strtod(line, &endptr); - // Ak nebolo načítané číslo alebo sú tam neplatné znaky if (endptr == line || *endptr != '\0') { printf("Nepodarilo sa nacitat polynom na %d mieste.\n", coef_index); - return 0; + return -1; } return 1; } @@ -39,7 +37,11 @@ int main() { int coef_count = 0; while (1) { - if (!read_double(&coef, coef_count + 2)) { + int status = read_double(&coef, coef_count + 2); + if (status == -1) { + return 0; + } + if (status == 0) { if (coef_count == 0) { return 1; }