From owner-freebsd-questions@FreeBSD.ORG Wed Sep 17 15:49:24 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 308661065673 for ; Wed, 17 Sep 2008 15:49:24 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from igloo.linux.gr (igloo.linux.gr [62.1.205.36]) by mx1.freebsd.org (Postfix) with ESMTP id 9E00D8FC22 for ; Wed, 17 Sep 2008 15:49:23 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from kobe.laptop (adsl83-215.kln.forthnet.gr [77.49.50.215]) (authenticated bits=128) by igloo.linux.gr (8.14.3/8.14.3/Debian-5) with ESMTP id m8HFnAXh030537 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Wed, 17 Sep 2008 18:49:16 +0300 Received: from kobe.laptop (kobe.laptop [127.0.0.1]) by kobe.laptop (8.14.3/8.14.3) with ESMTP id m8HFn9aj080253; Wed, 17 Sep 2008 18:49:09 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Received: (from keramida@localhost) by kobe.laptop (8.14.3/8.14.3/Submit) id m8HFn9oF080252; Wed, 17 Sep 2008 18:49:09 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) From: Giorgos Keramidas To: unga888@yahoo.com References: <417898.61773.qm@web57005.mail.re3.yahoo.com> Date: Wed, 17 Sep 2008 18:49:08 +0300 In-Reply-To: <417898.61773.qm@web57005.mail.re3.yahoo.com> (Unga's message of "Wed, 17 Sep 2008 06:32:56 -0700 (PDT)") Message-ID: <87od2mn56z.fsf@kobe.laptop> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-MailScanner-ID: m8HFnAXh030537 X-Hellug-MailScanner: Found to be clean X-Hellug-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=-3.848, required 5, autolearn=not spam, ALL_TRUSTED -1.80, AWL 0.55, BAYES_00 -2.60) X-Hellug-MailScanner-From: keramida@ceid.upatras.gr X-Spam-Status: No Cc: freebsd-questions@freebsd.org Subject: Re: How to split a C string by a string? 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: Wed, 17 Sep 2008 15:49:24 -0000 On Wed, 17 Sep 2008 06:32:56 -0700 (PDT), Unga wrote: > --- On Wed, 9/17/08, Giorgos Keramidas wrote: >> From: Giorgos Keramidas >> Subject: Re: How to split a C string by a string? >> To: unga888@yahoo.com >> Cc: freebsd-questions@freebsd.org >> Date: Wednesday, September 17, 2008, 6:17 PM >> On Wed, 17 Sep 2008 00:45:46 -0700 (PDT), Unga >> wrote: >> > Hi all >> > >> > I'm writing an C application on FreeBSD 7+. I need to split a >> > string by another string (ie. the delimiter is "xxx") similar to >> > strtok split a string by a single char. Is there a standard >> > function or is there a FreeBSD functions for this? >> >> You can use strstr() to look for the "xxx" delimited and split that >> that point: [snip sample code] > > Thank you very much for the reply. That is, there is no existing split > function. So I got to write to my own :) Yes, you have to roll our own. The standard C library doesn't have string splitting functions with a string as delimiter. It includes strtok(), strspn() and strcspn(), but these work with character sets as delimiters, not strings...