From owner-freebsd-questions@FreeBSD.ORG Mon Feb 18 23:03:59 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 22BDE16A419 for ; Mon, 18 Feb 2008 23:03:59 +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 C723A13C4F4 for ; Mon, 18 Feb 2008 23:03:58 +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 m1IN3sgA075906 for ; Mon, 18 Feb 2008 15:03:54 -0800 (PST) (envelope-from kline@thought.org) Received: by thought.org (nbSMTP-1.00) for uid 1002 kline@thought.org; Mon, 18 Feb 2008 15:03:54 -0800 (PST) Date: Mon, 18 Feb 2008 15:03:54 -0800 From: Gary Kline To: FreeBSD Mailing List Message-ID: <20080218230351.GA28000@thought.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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: Subject: 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: Mon, 18 Feb 2008 23:03:59 -0000 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 -- Gary Kline kline@thought.org www.thought.org Public Service Unix http://jottings.thought.org http://transfinite.thought.org #include #include main() { char *bp, buf[512], *tok, tstr[512]; static char *delim=" ", s1[256]="abc def ghi jkl mno."; bp = strcpy(buf, tstr); strcpy(bp, s1); /* bp filled with writable mem works like this, too */ while ((tok = strtok(bp, delim)) != NULL) { bp = NULL; printf("tok = [%s]\n", tok); } }