So I had posted a thread here called "Exception Handling" asking for help excuting this program. Then I discovered CodePad! ( So if any of the moderators could help me delete that thread it will be great! )

So I cleared up most of my errors. And I got an output. But I seem to getting a garbage value towards the end.

The objective is basically to handle "stack full" and "stack empty errors". So I push 3 values and I pop 4 values so that I can handle the error using try-throw-catch paradigm.

I'll post my Codepad Link here. Please help!

http://codepad.org/CP23icTR

Recommended Answers

All 3 Replies

Only two lines were the problem 26 and 27.
Just interchange the two lines and make ++top to top++.

26. stck[top]=op;
27. top++;

http://codepad.org/AwXVbQWk

You're off by 1. When you push the first element, it's at stck[1], because you increment top first. You are reading the values back from stck[2] to stck[0] (which is uninitialised), instead of stck[3] to stck[1].

Works!! Should've worked out the loops myself. Thank you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.