0

Hello. I am trying to run a simple postfix notation code. It builds but doesn't run. Can anyone tell me if it's my code that is stopping it from running?

Here is my code:

`int main(int argc, char *argv[]){`

        char *a = argv[1];
    int i, div, N = strlen(a);
    stack<int> save(N);

        cout << "Enter the postfix expression";
        cin >> a;

           for(i = 0; i<N; i++){
        if(a[i] == '+')
            save.push(save.pop() + save.pop());
        if(a[i] == '*')
            save.push(save.pop() * save.pop());
                if(a[i] == '-')
                        save.push(save.pop() - save.pop());
                if(a[i] == '/')
                        save.push(save.pop() / save.pop());
        if((a[i] >= '0') && (a[i] <= '9'))
            save.push(a[i] -'0');
        //while ((a[i] >= '0') && (a[i] <= '9'))
        //  save.push(10*save.pop() + (a[i++]-'0'));
           }

    cout << save.pop() <<endl;

    return 0;
}`
2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by np complete
1

Probably there is a pointer error. Can you provide the code for struct save ?

Edited by np complete

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.