diff --git a/du2/program.c b/du2/program.c index 2bba378..5af0590 100644 --- a/du2/program.c +++ b/du2/program.c @@ -5,22 +5,23 @@ #define LINE_SIZE 100 -int read_double(double *value) { +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; } char *endptr; *value = strtod(line, &endptr); if (endptr == line || (*endptr != '\0' && *endptr != '\n')) { - return 0; // Neplatný vstup + printf("Nepodarilo sa nacitat polynom na %d mieste.\n", coef_index); + return 0; } return 1; } int main() { double x; - if (!read_double(&x)) { + if (!read_double(&x, 1)) { printf("Chyba: Nepodarilo sa načítať hodnotu x.\n"); return 1; } @@ -30,7 +31,7 @@ int main() { int coef_count = 0; while (1) { - if (!read_double(&coef)) { + if (!read_double(&coef, coef_count + 2)) { if (coef_count == 0) { printf("Chyba: Neboli zadané žiadne koeficienty.\n"); return 1;