🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

4 total messages Started by Henry Zektser Sun, 07 May 2000 00:00
strtok()
#85
Author: Henry Zektser
Date: Sun, 07 May 2000 00:00
16 lines
1120 bytes
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 );
 }

H
Re: strtok()
#86
Author: Brian
Date: Sun, 07 May 2000 00:00
26 lines
1503 bytes
In article <8f547i$apj$1@bob.news.rcn.net>, "Henry Zektser" 
<kdentdev@hotmail.com> 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 );
> }
>
>H

Without seeing the whole source file, it is difficult to really assess 
where the problem might be.  It has been my experience that most 
programming books contain LOTS of errors in the sample code.  In 
addition, Microsoft tends to push products out the door that are 
somewhat half-baked.  Have you applied the latest & greatest OS service 
packs?  How about MSVC++ service packs?
Re: strtok()
#87
Author: John Harrison
Date: Mon, 08 May 2000 00:00
26 lines
1608 bytes
Henry Zektser <kdentdev@hotmail.com> wrote in message
news:8f547i$apj$1@bob.news.rcn.net...
> 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 );
>  }
>
> H
>

Works on my MSVC++ 6, and theres not much wrong with the code. Your problem
is probably elsewhere, perhaps you've put cerr into an error state, or
closed it or something.

john
Re: strtok()
#89
Author: Alan Donovan
Date: Tue, 09 May 2000 00:00
37 lines
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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads