Scoping question in C

Henry Spencer henry-lqW1N6Cllo0sV2N9l4h3zg at public.gmane.org
Tue Jun 14 00:54:28 UTC 2005


On Mon, 13 Jun 2005, Kevin Cozens wrote:
> >x=0;
> >while ( string[x] != 0 ) { x++; }
>
> Rather than use a loop you might as well just call strlen(). If you are 
> going to use a loop here you should add a counter in order to impose a 
> limit on the number of bytes should be copied based on what you think is 
> a reasonable upper limit...

And *that* operation is better done using memchr(), as it happens.
(memchr() gives you back a pointer, but you just subtract the start
pointer from that to yield the length.)

                                                          Henry Spencer
                                                       henry-lqW1N6Cllo0sV2N9l4h3zg at public.gmane.org

--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list