This commit is contained in:
Džubara 2024-02-28 15:46:06 +01:00
parent c2421587e8
commit ff0c230282

View File

@ -8,9 +8,7 @@
bool IsValidNumber(const char *line) { bool IsValidNumber(const char *line) {
char *endFtr; char *endFtr;
strtod(line, &endFtr); strtod(line, &endFtr);
if (endFtr == line){ return endFtr != line;
return false;
}
} }
int main() { int main() {
@ -26,6 +24,9 @@ int main() {
while (1) { while (1) {
if (fgets(line, MAX_LINE_LENGTH, stdin) == NULL || !IsValidNumber(line)) { if (fgets(line, MAX_LINE_LENGTH, stdin) == NULL || !IsValidNumber(line)) {
if (line[0] == '\n') {
break;
}
printf("Nepodarilo sa nacitat polynom na %d mieste. \n", coefficientIndex); printf("Nepodarilo sa nacitat polynom na %d mieste. \n", coefficientIndex);
return 1; return 1;
} }
@ -38,7 +39,7 @@ int main() {
} }
result = result * x; result = result * x;
coefficientIndex++; coefficientIndex++;
} }
printf("Vysledok je: %.2f\n", result); printf("Vysledok je: %.2f\n", result);