Date: Mon, 18 Feb 2008 18:41:52 -0800 From: Gary Kline <kline@thought.org> To: freebsd-questions@freebsd.org Subject: Re: is there an easier way? Message-ID: <200802181841.53221.kline@thought.org> In-Reply-To: <47BA1375.2010108@tundraware.com> References: <20080218230351.GA28000@thought.org> <47BA1375.2010108@tundraware.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Monday 18 February 2008 15:23:33 Tim Daneliuk wrote: > Gary Kline wrote: > > To my fellow C nerds, > > > > It's been a great manny years since I wrote this appended > > snippet. Now I can't remember why (of if ) I need all the > > strcpy() calls. Is there a simpler, more logical way of > > printing a bunch of string by snipping off the left-most? > > > > In short,, can anyone 'splain why strtok needs all this? > > > > tia, > > > > gary > > I don't think you need the copies. This works just as well: > > #include <stdio.h> > #include <string.h> > > main() > { > char *bp, *tok; > char *delim=" ", s1[256]="abc def ghi jkl mno."; > > bp = s1; /* Now both point to the literal string to be tokenized */ > > while ((tok = strtok(bp, delim)) != NULL) > { > bp = NULL; > printf("tok = [%s]\n", tok); > } > } I'll try this and compare it to what Joe sent. Also looking at publib.0.39 that LIW started years back. Ideally, I think it's better to malloc space because given my intended use, the strings could be relatively few ... or run into the thousands. Parenthetically, I'm trying to get use to kmail, and evolution, both of which are hard to save the attachment-of. mutt is so much easier. Thanks for the feedback. much appreciated, -- Gary Kline kline@thought.org www.thought.org Public Service Unix http://jottings.thought.org http://transfinite.thought.org
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200802181841.53221.kline>