From owner-freebsd-questions@FreeBSD.ORG Tue Feb 19 02:41:58 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 43C0D16A41B for ; Tue, 19 Feb 2008 02:41:58 +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 DDEA313C458 for ; Tue, 19 Feb 2008 02:41:57 +0000 (UTC) (envelope-from kline@thought.org) Received: from tao.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 m1J2fr9b077162; Mon, 18 Feb 2008 18:41:53 -0800 (PST) (envelope-from kline@thought.org) From: Gary Kline To: freebsd-questions@freebsd.org Date: Mon, 18 Feb 2008 18:41:52 -0800 User-Agent: KMail/1.9.7 References: <20080218230351.GA28000@thought.org> <47BA1375.2010108@tundraware.com> In-Reply-To: <47BA1375.2010108@tundraware.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200802181841.53221.kline@thought.org> 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 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 02:41:58 -0000 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 > #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); > } > } 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