www.digitalmars.com         C & C++   DMDScript  

c++ - char '9' to int 9

reply "Andrew Edwards" <edwardsac spamfreeusa.com> writes:
I am trying to create a program that evaluates postfix-expressions.
Currently I read the expression character-by-character from the user and
check to see if it is a digit or one of four arithmetic operators: +, -, *,
and /. If it is, I concatenate it onto a string. I then index through the
string, pushing digits unto a stack. When an operator is encountered, I pop
off the top two operands, perform the operation, and push the result back
unto the stack.

If char '9' is encountered I want to push the integer 9 onto the stack, not
57 (i.e. '9'). How do I accomplish this?

Thanks,
Andrew
Jun 22 2003
parent reply "Gisle Vanem" <giva users.sourceforge.net> writes:
"Andrew Edwards" <edwardsac spamfreeusa.com>:

 If char '9' is encountered I want to push the integer 9 onto the stack, not
 57 (i.e. '9'). How do I accomplish this?
You push '9' - '0' = 9 onto the stack. --gv
Jun 22 2003
parent "Andrew Edwards" <edwardsac spamfreeusa.com> writes:
You are a lifesaver...
Thanks..
Andrew
Jun 22 2003