Обновить du2/program.c
This commit is contained in:
parent
8ec7513538
commit
1c40d2ffff
@ -8,11 +8,11 @@
|
||||
int read_double(double *value, int coef_index) {
|
||||
char line[LINE_SIZE];
|
||||
if (fgets(line, LINE_SIZE, stdin) == NULL) {
|
||||
return 0;
|
||||
return 0; // Chyba pri čítaní
|
||||
}
|
||||
line[strcspn(line, "\r\n")] = 0;
|
||||
|
||||
// Skontrolujeme, či je riadok prázdny
|
||||
|
||||
if (strlen(line) == 0) {
|
||||
return 0;
|
||||
}
|
||||
@ -20,6 +20,7 @@ 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;
|
||||
@ -30,7 +31,6 @@ int read_double(double *value, int coef_index) {
|
||||
int main() {
|
||||
double x;
|
||||
if (!read_double(&x, 1)) {
|
||||
printf("Chyba: Nepodarilo sa načítať hodnotu x.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -41,10 +41,9 @@ int main() {
|
||||
while (1) {
|
||||
if (!read_double(&coef, coef_count + 2)) {
|
||||
if (coef_count == 0) {
|
||||
printf("Chyba: Neboli zadané žiadne koeficienty.\n");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
result = result * x + coef;
|
||||
coef_count++;
|
||||
|
Loading…
Reference in New Issue
Block a user