From 863f360310ba04ae02a0970f39d6ee259d0d214a Mon Sep 17 00:00:00 2001 From: Yevhen Kozirovskyi Date: Thu, 17 Oct 2024 17:02:11 +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 | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/cv3/program.c b/cv3/program.c index 6c3313e..c386dbd 100644 --- a/cv3/program.c +++ b/cv3/program.c @@ -47,11 +47,11 @@ int main() { while (fgets(bufer, sizeof(bufer), stdin) != NULL) { char* konec; double chislo = strtod(bufer, &konec); + char c = konec[0]; - if (*konec == '\n' && *bufer != '\n' && *bufer != ' ') { + if (c == '\n' && *bufer != '\n' && *bufer != ' ') { push(&stek, chislo); - } else if (strcmp(konec, "+\n") == 0) { - + } else if (c == '+') { if (isEmpty(&stek)) { printf("no input\n"); exit(1); @@ -63,7 +63,7 @@ int main() { } double a = pop(&stek); push(&stek, a + b); - } else if (strcmp(konec, "-\n") == 0) { + } else if (c == '-') { if (isEmpty(&stek)) { printf("no input\n"); exit(1); @@ -75,7 +75,7 @@ int main() { } double a = pop(&stek); push(&stek, a - b); - } else if (strcmp(konec, "*\n") == 0) { + } else if (c == '*') { if (isEmpty(&stek)) { printf("no input\n"); exit(1); @@ -87,7 +87,7 @@ int main() { } double a = pop(&stek); push(&stek, a * b); - } else if (strcmp(konec, "/\n") == 0) { + } else if (c == '/') { if (isEmpty(&stek)) { printf("no input\n"); exit(1); @@ -97,21 +97,18 @@ int main() { printf("no input\n"); exit(1); } - double a = pop(&stek); if (b == 0) { printf("division by zero\n"); return 0; - exit(1); } push(&stek, a / b); - } else if (isalpha(konec[-1])) { + } else if (isalpha(c)) { printf("bad input\n"); - exit(1); return 0; } else { - printf("bad input\n"); - exit(1); + printf("no input\n"); + return 0; } for (int i = 0; i < stek.vershina; i++) { printf("%.2lf ", stek.chisla[i]);