Path: utzoo!attcan!uunet!cs.utexas.edu!usc!ucsd!ucbvax!ulysses!srn From: srn@ulysses.att.com (Shirish R Nadkarni) Newsgroups: comp.lang.c Subject: Character arrays Keywords: FORMULA SCANNING Message-ID: <13281@ulysses.att.com> Date: 3 Jul 90 16:40:55 GMT Organization: AT&T Bell Laboratories, Murray Hill Lines: 25 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@ulysses.att.com)