Article View: att.lang.c++
Article #89Re: strtok()
From: Alan Donovan
Date: Tue, 09 May 2000 00:00
Date: Tue, 09 May 2000 00:00
37 lines
1966 bytes
1966 bytes
Henry Zektser wrote:
>
> Hey all, I'm using MSVC++ 6.0 Enterprise and strtok(). The following code
> builds, and executes, but I get no output on cerr, is this a problem with
> strtok? MS's sample code doesnt work either...
> trying to do this:
> char LineContents[]="blah blah blah";
> char seps[]=" \n";
>
> token = strtok(LineContents, seps);
> cerr << "token (bl): " << token << endl;
> while( token != NULL )
> {
> cerr << "token: " << token << endl;
> token = strtok( NULL, seps );
> }
Without commenting on your program, I would advise you that strtok is
often frowned upon because:
1. it's no good with const strings.
2. the identity of the separating character is lost.
3. it maintains static data and is therefore not threadsafe or library
safe -- use the nonstandard strtok_r or better still, roll your own.
Oh, and you need to check that "token" is non-NULL (although your
example will be ok).
MSVC5 strtok used to work fine for me (I don't use it any more though).
alan
--
------------------------------------------------------------------------
Alan Donovan adonovan@imerge.co.uk http://www.imerge.co.uk
Imerge Ltd. +44 1223 875265
Technical Details
Message-ID:
<3917D289.10BC5CD1@imerge.co.uk>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<8f547i$apj$1@bob.news.rcn.net>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109fba,e2c93d4356ee1452 X-Google-Attributes: gid109fba,public X-Google-Thread: 10d4ba,e2c93d4356ee1452 X-Google-Attributes: gid10d4ba,public From: Alan Donovan <adonovan@imerge.co.uk> Subject: Re: strtok() Date: 2000/05/09 Message-ID: <3917D289.10BC5CD1@imerge.co.uk> X-Deja-AN: 621032053 Content-Transfer-Encoding: 7bit References: <8f547i$apj$1@bob.news.rcn.net> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@uk.uu.net X-Trace: soap.pipex.net 957862538 5017 194.216.39.131 (9 May 2000 08:55:38 GMT) Organization: Imerge Ltd. Mime-Version: 1.0 NNTP-Posting-Date: 9 May 2000 08:55:38 GMT Newsgroups: att.lang.c++,comp.lang.c++