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]);