From f71ad133b9ab869a6b97b93fadb44fa83be5abbf Mon Sep 17 00:00:00 2001 From: Yevhen Kozirovskyi Date: Thu, 17 Oct 2024 16:54:08 +0000 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20cv3/program.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cv3/program.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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);