diff --git a/cv3/program.c b/cv3/program.c index 6664f3a..b64bce6 100644 --- a/cv3/program.c +++ b/cv3/program.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -46,13 +47,14 @@ int main() { while (fgets(bufer, sizeof(bufer), stdin) != NULL) { char* konec; double chislo = strtod(bufer, &konec); + if (chislo == 0 && strcmp(bufer, "0\n") != 0) { + printf("bad input\n"); + exit(1); + } if (*konec == '\n' && *bufer != '\n' && *bufer != ' ') { - if (konec - bufer == 1) { - printf("bad input\n"); - exit(1); - } push(&stek, chislo); } else if (strcmp(konec, "+\n") == 0) { + if (isEmpty(&stek)) { printf("no input\n"); exit(1); @@ -106,6 +108,9 @@ int main() { exit(1); } push(&stek, a / b); + } else if (isalpha(konec[-1])) { + printf("bad input\n"); + exit(1); } else { printf("bad input\n"); exit(1);