From b7c0451cd2aebfd1fd24d7f6cc8a5e78750b911b Mon Sep 17 00:00:00 2001 From: inex Date: Sat, 7 Mar 2020 14:21:02 +0300 Subject: [PATCH] Fix bug with substraction --- task2/task2.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/task2/task2.c b/task2/task2.c index 06beca8..a0f908c 100644 --- a/task2/task2.c +++ b/task2/task2.c @@ -97,7 +97,7 @@ void divide(STACK* st) { int parse(char *s, STACK* stack) { double operand = 0; char *endptr; - if (*s == '-' && *(s+1) != '\0') { + if ((*s == '-') && (*(s+1) == '\0')) { substract(stack); return 0; } else if (*s == '+') { @@ -119,7 +119,7 @@ int parse(char *s, STACK* stack) { int main(int argc, char **argv) { - STACK* operands = init_stack(100); + STACK* operands = init_stack(argc); int error; while(*++argv) { error = parse(*argv, operands); @@ -129,6 +129,7 @@ int main(int argc, char **argv) { } } int i; + printf("Stack status:\n"); for (i = (operands -> cnt); i > 0; i--) printf("%f\n", pop(operands)); return 0; }