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; }