From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <3EB90B63.30401@ameritech.net> From: northern snowfall User-Agent: Mozilla/5.0 (X11; U; SunOS sun4u; en-US; rv:0.9.4.1) Gecko/20020518 Netscape6/6.2.3 MIME-Version: 1.0 To: 9fans@cse.psu.edu Subject: Re: [9fans] same functions everywhere References: <20030501160047.7231.qmail@g.bio.cse.psu.edu> <000c01c3147c$c7665ae0$7b83773e@SOMA> <3EB8E817.4090609@ameritech.net> <20030507124006.D26796@cackle.proxima.alt.za> <3EB9049D.50500@ameritech.net> <20030507142511.F26796@cackle.proxima.alt.za> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Date: Wed, 7 May 2003 08:34:27 -0500 Topicbox-Message-UUID: a16ed29e-eacb-11e9-9e20-41e7f4b1d025 > > >Not really. Mostly, one wants the location where the item was found >(x, in my example) which your function discards. Sometimes, one may >want to take action if the item is not found. > I saw this comin' as soon as I hit the send button. Oh well. Simply add in functionality to determine the slot of the first false test. #include #include enum { true, false, }; // returns true if all slots EQUATE to val // returns false if all slots do NOT equate to val // side effects: equates *pos to the first slot that tests false int gotvalue/*?*/(int * a, uint len, int val, uint * pos) { uint ua; for(ua = 0; ua < len; ua++) { if(a[ua] != val) { *pos = ua; return false; } } return true; } int main(int argc, char * argv[]) { int a[100]; uint pos; // somehow "a" gets filled with values if(gotvalue(&a[0], sizeof(a), 0xdeadca75, &pos) == true) print("yay, we're true! \ n"); else print("negate at slot %ud \n", pos); exits(0); }