Character arrays
Shirish R Nadkarni
srn at ulysses.att.com
Wed Jul 4 02:40:55 AEST 1990
Does anyone have a piece of code that can scan a formula ? I will
try to explain that a bit:
Suppose I have 4 numbers (these will be stored in variable names, but
for the time we will assume that they are stored under 1, 2, 3 and 4).
I need to calculate
total = 1 * 2 + 3 * 4 OR (1*2) + 3 + 4 OR 1 + (2/3) +4
(these are examples and all the formulas above are obviously not
equivalent)
The input would be in the form of a character array that would be
the right side of the above equation. There may be parentheses present.
(In fact +,-,*,/, (, and ) are legal characters. It can be assumed that
the variables are 1, 2, 3, and 4)
Also blanks may not always be there. I am using 'scanf' to fetch the
input and store that into an array. My job is to 'interpret' the formula
and then process the corresponding variables accordingly to obtain
'total'.
P.S.: the maximum number of variables will be 10.
Thanks in advance
-Shirish (ulysses!srn or srn at ulysses.att.com)
More information about the Comp.lang.c
mailing list