From 2e265581c9e38f55a4c04b230704d1f5722d4c50 Mon Sep 17 00:00:00 2001 From: Bohdana Marchenko Date: Thu, 6 Mar 2025 13:04:49 +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 | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/du2/program.c b/du2/program.c index 0080267..3a7fbb5 100644 --- a/du2/program.c +++ b/du2/program.c @@ -12,7 +12,9 @@ int read_double(double *value, int coef_index) { return 0; } - line[strcspn(line, "\r\n")] = 0; + + line[strcspn(line, "\r\n")] = 0; + if (strlen(line) == 0) { return 0; @@ -21,12 +23,9 @@ int read_double(double *value, int coef_index) { char *endptr; *value = strtod(line, &endptr); + if (endptr == line || *endptr != '\0') { - if (coef_index == 1) { - printf("Nepodarilo sa nacitat zaklad x\n"); - } else { - printf("Nepodarilo sa nacitat polynom na %d mieste.\n", coef_index); - } + printf("Nepodarilo sa nacitat polynom na %d mieste.\n", coef_index); return -1; } @@ -36,7 +35,6 @@ int read_double(double *value, int coef_index) { int main() { double x; - // Read base `x` if (!read_double(&x, 1)) { return 1; } @@ -47,7 +45,6 @@ int main() { while (1) { coef_count++; - int status = read_double(&coef, coef_count); if (status == -1) { @@ -56,7 +53,7 @@ int main() { if (status == 0) { if (coef_count == 1) { - return 1; + return 1; } break; } @@ -64,6 +61,7 @@ int main() { result = result * x + coef; } - printf("Vysledok je: %.2f\n", result); + + printf("Vysledok je: %.2f\n", result); return 0; -} +} \ No newline at end of file