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

This commit is contained in:
Bohdana Marchenko 2025-03-06 10:46:00 +00:00
parent 0690bb3eba
commit 2f00fb6a0b

View File

@ -10,11 +10,20 @@ int read_double(double *value, int coef_index) {
if (fgets(line, LINE_SIZE, stdin) == NULL) { if (fgets(line, LINE_SIZE, stdin) == NULL) {
return 0; return 0;
} }
line[strcspn(line, "\r\n")] = 0;
if (strlen(line) == 0) {
return 0;
}
char *endptr; char *endptr;
*value = strtod(line, &endptr); *value = strtod(line, &endptr);
if (endptr == line || (*endptr != '\0' && *endptr != '\n')) {
if (endptr == line || *endptr != '\0') {
printf("Nepodarilo sa nacitat polynom na %d mieste.\n", coef_index); printf("Nepodarilo sa nacitat polynom na %d mieste.\n", coef_index);
return 0; exit(1);
} }
return 1; return 1;
} }