is there an easier way?
Gary Kline
kline at thought.org
Tue Feb 19 04:34:51 UTC 2008
On Mon, Feb 18, 2008 at 05:23:33PM -0600, 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);
> }
> }
>
>
>
> --
> ----------------------------------------------------------------------------
> Tim Daneliuk tundra at tundraware.com
> PGP Key: http://www.tundraware.com/PGP/
Giving up kmail..... this works too, thanks. But only with
a fixed buffer --obv'ly 256 in this case. still pondering... .
>
--
Gary Kline kline at thought.org www.thought.org Public Service Unix
http://jottings.thought.org http://transfinite.thought.org
More information about the freebsd-questions
mailing list