Yes, the program is wrong (nacct is out of the valid array area at that 
point).  I've fixed it, thanks.

Henry Rich


On 1/25/2011 11:18 AM, Ron Jeffries wrote:
> Hi. I'm Ron Jeffries. I've been experimenting with J language with
> advice from Tracy Harms, Raul Miller, Henry Rich, and Gilles
> Kirouac. (Thanks to you all, and to anyone I've missed.)
>
> Gilles, in particular, detected that I may have dived in too deep,
> and suggested that I go back to J for C programmers and work through
> that. I had started with it but didn't really find it tasty, but on
> his advice I'm going again.
>
> I noticed in an early example, the accounts one, this patch of C code:
>
>    while(3 == fscanf(fid,"%f%f%f",acctno,xactnday,xactnamt) {
>       for(acctx = 0;acct[acctx].ano != acctno;++acctx);
>       acct[nacct].weightbal +=
>          acct[nacct].currbal * (xactnday - acct[nacct].prevday);
>       acct[nacct].currbal += xactnamt;
>       acct[nacct].prevday = xactnday;
>    }
>
> A similar patch appears at the end of the example.
>
> I'm quite rusty on C but it appears to me that the for loop finds
> the value of acctx such that we have the right account number acctno
> ... but that the subsequent code updates account number nacct,
> which, as the incremented value of nacct after the input read loop,
> is in fact an uninitialized account struct.
>
> Am I missing something? If not, maybe the example in JfC needs
> updating. If nothing else, this surely shows that J is not subject
> to this kind of error, or at least not quite so easily.
>
> I'm sure I'll be back with beginner J questions soon. Thanks!
>
> Ron Jeffries
> www.XProgramming.com
> If not now, when?  -- The Talmud
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to