[edit] @
PATI [/edit]
It didn't work fine. And I don't mean to scare you off, but if you don't know what OP's program does, how can you help him?
@
pacman169
The problem is the odd way you are handling the command-line arguments. You've got
two fencepost errors in there with argc/argv, and one with your stack.
Treat
argc and
argv as if they were constants. Your main program, then, should look like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
int main( int argc, char** argv )
{
int n;
int op2;
for (n = 1; n < argc; n++)
{
switch (argv[n][0])
{
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
push(atoi(argv[n]));
break;
case '+':
push(pop() + pop());
break;
etc
}
}
}
|
Watch your condition on line 90. It should be
if (next >= STACKSIZE)
, since stack[1000] is an invalid position.
Your program is otherwise fairly well-designed. Good job!
I personally would recommend you spend some time trying to fix your indentation (particularly, match up if and else statements) and pick a single style for you use of braces.
Hope this helps.