www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

c++ - char '9' to int 9

↑ ↓ ← "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
↑ ↓ "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
↑ ↓ → "Andrew Edwards" <edwardsac spamfreeusa.com> writes:
You are a lifesaver...
Thanks..
Andrew
Jun 22 2003