Обновить du2/program.c

This commit is contained in:
Bohdana Marchenko 2025-03-06 10:56:22 +00:00
parent 1c40d2ffff
commit 563a7af4f2

View File

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