Search code examples
c++stringextractpostfix-notation

extracting numbers and characters from a string, which doesn't follow a specific format? (postfix calculator)


I'm having trouble separating numbers and characters from my input string. The purpose of my program is to add,subtract,multiply and divide in postfix so i cant predict the input form as it can be anything from 2 2 3 + * (answer being 10) to 2 2 + 3 * (answer being 12). So i cant use sscanf to extract the numbers and the operator character without having a specific format to the input string. What should i do here?


Solution

  • Well, to process postfix you're going to want to implement a stack, so you should push each number onto a stack as you get it, each operator pops two off the stack and pushes the result back.