From owner-freebsd-questions@FreeBSD.ORG Mon Feb 18 23:23:39 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 7644E16A419 for ; Mon, 18 Feb 2008 23:23:39 +0000 (UTC) (envelope-from tundra@tundraware.com) Received: from ozzie.tundraware.com (ozzie.tundraware.com [75.145.138.73]) by mx1.freebsd.org (Postfix) with ESMTP id 3879013C474 for ; Mon, 18 Feb 2008 23:23:38 +0000 (UTC) (envelope-from tundra@tundraware.com) Received: from [192.168.0.2] (viper.tundraware.com [192.168.0.2]) (authenticated bits=0) by ozzie.tundraware.com (8.14.2/8.14.2) with ESMTP id m1INNWu9016996 (version=TLSv1/SSLv3 cipher=DHE-DSS-AES256-SHA bits=256 verify=NO); Mon, 18 Feb 2008 17:23:33 -0600 (CST) (envelope-from tundra@tundraware.com) Message-ID: <47BA1375.2010108@tundraware.com> Date: Mon, 18 Feb 2008 17:23:33 -0600 From: Tim Daneliuk Organization: TundraWare Inc. User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 To: Gary Kline References: <20080218230351.GA28000@thought.org> In-Reply-To: <20080218230351.GA28000@thought.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-tundraware.com-MailScanner-Information: Please contact the ISP for more information X-tundraware.com-MailScanner: Found to be clean X-tundraware.com-MailScanner-From: tundra@tundraware.com X-Spam-Status: No 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 Reply-To: tundra@tundraware.com List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 Feb 2008 23:23:39 -0000 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/