Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 18 Feb 2008 18:19:07 -0500
From:      Joe Marcus Clarke <marcus@marcuscom.com>
To:        Gary Kline <kline@thought.org>
Cc:        FreeBSD Mailing List <freebsd-questions@freebsd.org>
Subject:   Re: is there an easier way?
Message-ID:  <1203376747.32200.21.camel@shumai.marcuscom.com>
In-Reply-To: <20080218230351.GA28000@thought.org>
References:  <20080218230351.GA28000@thought.org>

next in thread | previous in thread | raw e-mail | index | archive | help

--=-LIi0OgAAiJXzGTs5nffo
Content-Type: multipart/mixed; boundary="=-uqBPJIhpwgUmcjToi5jn"


--=-uqBPJIhpwgUmcjToi5jn
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable


On Mon, 2008-02-18 at 15:03 -0800, Gary Kline wrote:
> 	To my fellow C nerds,
>=20
> 	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=20
> 	printing a bunch of string by snipping off the left-most?
>=20
> 	In short,, can anyone 'splain why strtok needs all this?

Here are two examples, one with dynamically allocated memory, and one
with static memory.  You need the copy so that you allocate writable
space for strtok() to fill in the NUL bytes.  I imagine there are even
better/easier ways, but both of these work okay.

Joe

--=20
PGP Key : http://www.marcuscom.com/pgp.asc

--=-uqBPJIhpwgUmcjToi5jn--

--=-LIi0OgAAiJXzGTs5nffo
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (FreeBSD)

iEYEABECAAYFAke6EmcACgkQb2iPiv4Uz4cLhwCdFBIBWFZ3cQJQ4tPPXZvccC3N
FT4AnjBH/DS6qXdi6uSK93LqUyt4rF8o
=LwIz
-----END PGP SIGNATURE-----

--=-LIi0OgAAiJXzGTs5nffo--




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1203376747.32200.21.camel>