Fix bug with substraction
This commit is contained in:
parent
bf45a0eec8
commit
b7c0451cd2
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue