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