From 2f00fb6a0b4b4a7aebfba3544b4821cbda6a62e5 Mon Sep 17 00:00:00 2001 From: Bohdana Marchenko Date: Thu, 6 Mar 2025 10:46:00 +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 | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/du2/program.c b/du2/program.c index 5af0590..285776e 100644 --- a/du2/program.c +++ b/du2/program.c @@ -9,12 +9,21 @@ int read_double(double *value, int coef_index) { char line[LINE_SIZE]; if (fgets(line, LINE_SIZE, stdin) == NULL) { return 0; + } + + line[strcspn(line, "\r\n")] = 0; + + + if (strlen(line) == 0) { + return 0; } + char *endptr; *value = strtod(line, &endptr); - if (endptr == line || (*endptr != '\0' && *endptr != '\n')) { + + if (endptr == line || *endptr != '\0') { printf("Nepodarilo sa nacitat polynom na %d mieste.\n", coef_index); - return 0; + exit(1); } return 1; }