Fix bug with substraction

This commit is contained in:
Inex Code 2020-03-07 14:21:02 +03:00
parent bf45a0eec8
commit b7c0451cd2

View file

@ -97,7 +97,7 @@ void divide(STACK* st) {
int parse(char *s, STACK* stack) { int parse(char *s, STACK* stack) {
double operand = 0; double operand = 0;
char *endptr; char *endptr;
if (*s == '-' && *(s+1) != '\0') { if ((*s == '-') && (*(s+1) == '\0')) {
substract(stack); substract(stack);
return 0; return 0;
} else if (*s == '+') { } else if (*s == '+') {
@ -119,7 +119,7 @@ int parse(char *s, STACK* stack) {
int main(int argc, char **argv) { int main(int argc, char **argv) {
STACK* operands = init_stack(100); STACK* operands = init_stack(argc);
int error; int error;
while(*++argv) { while(*++argv) {
error = parse(*argv, operands); error = parse(*argv, operands);
@ -129,6 +129,7 @@ int main(int argc, char **argv) {
} }
} }
int i; int i;
printf("Stack status:\n");
for (i = (operands -> cnt); i > 0; i--) printf("%f\n", pop(operands)); for (i = (operands -> cnt); i > 0; i--) printf("%f\n", pop(operands));
return 0; return 0;
} }