[Discuss] 'C' string tokenizer for those who hate strtok

p.willis at telus.net p.willis at telus.net
Thu Jun 29 13:37:05 PDT 2006


Quoting p.willis at telus.net:

> Quoting Paul Nienaber <phox at phox.ca>:
> 
> > Buffer from nowhere?  POSIX has mandated strtok_r() for like... ever. 
> > strtok() _is_ stupid.  It's also about one more line to use strchr() or
> > one can use BSD strsep(), or whatever...
> > 
> > ~p
> 
> 
> Paul,
> 
> It's fluff. It's a learning excercise for 'C' linked lists for beginners.
> 
> It's entertainment...or would you rather read about partitioning hard drives
> 200 more times.
> 
> Peter


I should also note that this technique is better than all 
of the above mentioned tokenization routines in that it doesn't
destroy the original data. It always makes me wonder about
libraries when the actual 'man pages' say to avoid the routine
if possible.
(ie: strtok, strtok_r, and strsep all come with this warning)

A second point regarding the storage is that the deallocation
is obviated by this technique reducing memory leaks. But that's
splitting hairs since free() also works [most of the time] for
some of the other routines.

Peter

Peter



More information about the Discuss mailing list