I'm working on my c skills to better undestand the Hmh stream. I'm doing math(with khan academy) and c (with the famous K&R book).
Sometimes I really don't get the questions in the exercises(not the actual solution but just the meaning of what is expected me to do!) anyway I managed to get to the 4.4 exercise doing all of them with minor struggles but sometimes overdoing things a bit...
The exercise is about a polish reverse calculator and the given code is this one:
It's not really the given code I added the % operator and negative numbers implementation(that was the previous exercise and that one made perfectly sense), now the next one is asking:
Add commands to print the top element of the stack without popping, to duplicate it, and to swap the top two elements. Add a command to clear the stack.
The stack is just the "val" array, and for what I can undestand it gets cleared every line of input since every time a value gets popped the index decrese, so basically every new line the new values are pushed always from the beginning of what they call "stack"(the val array). So the old values are overwritten.
I don't get it.
I find myself tempted to not pop the values but just read them so that the "stack" can grow then I can operate on previous stored data, but I know the exercise is probably just asking me to do operations on just the single line of input.
Sorry for my bad english!
I'm not looking for a solution just wondering if it's me or it's the textbook a bit weird sometimes!