Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!ucsd!ames!bionet!agate!volcano.Berkeley.EDU!dankg From: dankg@volcano.Berkeley.EDU (Dan KoGai) Newsgroups: comp.lang.c Subject: Re: Character arrays Keywords: FORMULA SCANNING Message-ID: <1990Jul5.091706.10999@agate.berkeley.edu> Date: 5 Jul 90 09:17:06 GMT References: <13281@ulysses.att.com> Sender: usenet@agate.berkeley.edu (USENET Administrator;;;;ZU44) Reply-To: dankg@volcano.Berkeley.EDU (Dan KoGai) Organization: ucb Lines: 25 In article <13281@ulysses.att.com> srn@ulysses.att.com (Shirish R Nadkarni) writes: >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 Take a look at the source of expr: expr is a unix utility that does exactly what you want: You give formula as an arguments, which symobols and numbers separated with space. I had to do if from scratch in my CS cource. Maybe it's a good practice if you do it by yourself. It was quite benefitial for me. But precedence handling was pain in the neck... ---------------- ____ __ __ + Dan The "expr 1 / 0" Man ||__||__| + E-mail: dankg@ocf.berkeley.edu ____| ______ + Voice: +1 415-549-6111 | |__|__| + USnail: 1730 Laloma Berkeley, CA 94709 U.S.A |___ |__|__| + Oxymorons: Usable MS-DOS is oxymoron. |____|____ + Multitasking Mac is oxymoron. \_| | + Secure Unix is oxymoron