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