From owner-freebsd-questions@FreeBSD.ORG Tue Feb 19 04:34:50 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E9D5916A49A for ; Tue, 19 Feb 2008 04:34:50 +0000 (UTC) (envelope-from kline@thought.org) Received: from aristotle.thought.org (dsl231-043-140.sea1.dsl.speakeasy.net [216.231.43.140]) by mx1.freebsd.org (Postfix) with ESMTP id 87B6D13C4DB for ; Tue, 19 Feb 2008 04:34:50 +0000 (UTC) (envelope-from kline@thought.org) Received: from thought.org (tao.thought.org [10.47.0.250]) (authenticated bits=0) by aristotle.thought.org (8.14.2/8.14.2) with ESMTP id m1J4YdJ9077764; Mon, 18 Feb 2008 20:34:41 -0800 (PST) (envelope-from kline@thought.org) Received: by thought.org (nbSMTP-1.00) for uid 1002 kline@thought.org; Mon, 18 Feb 2008 20:34:41 -0800 (PST) Date: Mon, 18 Feb 2008 20:34:39 -0800 From: Gary Kline To: Tim Daneliuk Message-ID: <20080219043438.GA32855@thought.org> References: <20080218230351.GA28000@thought.org> <47BA1375.2010108@tundraware.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <47BA1375.2010108@tundraware.com> User-Agent: Mutt/1.4.2.3i X-Organization: Thought Unlimited. Public service Unix since 1986. X-Of_Interest: With 21 of service to the Unix community. X-Spam-Status: No, score=-4.4 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham version=3.2.3 X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on aristotle.thought.org Cc: FreeBSD Mailing List Subject: Re: is there an easier way? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Feb 2008 04:34:51 -0000 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 > #include > > 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@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@thought.org www.thought.org Public Service Unix http://jottings.thought.org http://transfinite.thought.org