Mailinglist Archive: opensuse (1690 mails)

< Previous Next >
Re: [opensuse] c - Segmentation fault on 11.4 - need help figuring out (strtod?)
On 11/03/2011 07:57 AM, David C. Rankin wrote:
On 11/03/2011 06:24 AM, Anton Aylward wrote:
Roger Oberholtzer said the following on 11/03/2011 04:58 AM:
On Wed, 2011-11-02 at 21:34 -0300, Cristian Rodríguez wrote:
On 02/11/11 20:49, David C. Rankin wrote:

Thank you Christian! I would have looked at this for days and not
caught the '<=' issue.

Well deserved then :-D , unless you are doing this as a learning
experience or plan to roll such code in an intensive math computing
environment, you are picking the wrong language. python or ruby will do
the trick just fine.

C is never the wrong language. It is the tasks that are wrong :) ;)

Add Tcl to the list of alternatives.

And shell.
The bash shell is an incredibly powerful programming language and very
easy to debug.

<snip>

I actually did the little area calc in bash first :)

for i in 5 7 4 16 9 15 11 13 12; do \
printf "r: %2s area: %7.3f\n" $i $(calc "3.1459265358*$i*$i") \
done


The full script, with input checking would look like this:

#!/bin/bash

for i in $@; do
[ $i -eq $i ] &>/dev/null || continue
printf "r: %2s area: %7.3f\n" $i $(calc "3.14592638*$i*$i")
done

exit 0

Save as area.sh, then

sh area.sh 1 2 3 dog 4 5

r: 1 area: 3.146
r: 2 area: 12.584
r: 3 area: 28.313
r: 4 area: 50.335
r: 5 area: 78.648

Oh, don't forget to install 'calc' first:

http://www.isthe.com/chongo/tech/comp/calc/

tar -xjf calc-2.12.4.4.tar.bz2
cd calc-2.12.4.4
make all
sudo make install

or see:

http://sourceforge.net/projects/calc/files/calc/2.12.4.3/

There are src.rpms there, but they don't build on 11.4 and I haven't taken time to debug. Job left to the interested reader :)


--
David C. Rankin, J.D.,P.E.
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
To contact the owner, e-mail: opensuse+owner@xxxxxxxxxxxx

< Previous Next >