Your push and pop operations need to be the exact reverse of each other.
So if push is
stackarray[index] = v
index++ //increment last
pop must be
index-- //decrement first
return stackarray[index]
otherwise, pop will always return the value from one slot after the most recently pushed value.
Debugging a program that uses command-line arguments shouldn't be much different from debugging any other program. But you may need to read the debugger's documentation to learn how to pass the arguments to the program. In gdb:
gdb> break main
gdb> run arg1 arg2 arg3 ...
That is, add the arguments to the run
line, as if run
were the name of the program.