Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #59136

Re: what the fork is wrong with strtok_r

From James Kuyper <jameskuyper@verizon.net>
Newsgroups comp.lang.c
Subject Re: what the fork is wrong with strtok_r
Date 2015-03-28 10:57 -0400
Organization A noiseless patient Spider
Message-ID <mf6ffi$jqa$1@dont-email.me> (permalink)
References <mf6eja$cls$1@reader1.panix.com>

Show all headers | View raw


On 03/28/2015 10:41 AM, what wrote:
> The docs are terrible for strtok_r and I can not predict how it will 
> behave.  I have a simple text string from stdin to tokenize on " \n" and  
> it seems that this is very difficult task for the C programming language. 

That's not a useful question. To get a useful answer, you should provide
the following:
1. The source code that you're using to read the string from stdin and
pass it to strtok_r.
2. The complete text that you want to tokenize.
3. An explanation of what you expected to happen.
4. The evidence provided by the output from your program that makes you
think that something else happened.

Note: if you're using gets() to read the text string, '\n' characters
will be replaced with '\0', which would make tokenizing on '\n' a little
difficult. If that fact is completely irrelevant to your problem, that
demonstrates the need for item 1.

For your own personal investigation, I'd recommend breaking this up into
two separate investigations:
A. Reading the string from input. Check to make sure that what you've
read from input is precisely what you expected to read. This includes
terminating null characters and newline characters.
B. Create the string inside your program without reading it from stdin.
Pass it to strtok_r(), and see what the behavior is.
-- 
James Kuyper

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

what the fork is wrong with strtok_r what <ceo@iran.gov> - 2015-03-28 14:41 +0000
  Re: what the fork is wrong with strtok_r James Kuyper <jameskuyper@verizon.net> - 2015-03-28 10:57 -0400
    Re: what the fork is wrong with strtok_r Keith Thompson <kst-u@mib.org> - 2015-03-28 17:39 -0700
      Re: what the fork is wrong with strtok_r James Kuyper <jameskuyper@verizon.net> - 2015-03-28 21:33 -0400
      Re: what the fork is wrong with strtok_r ruben safir <ruben@mrbrklyn.com> - 2015-03-29 03:36 -0400
      Re: what the fork is wrong with strtok_r ruben safir <ruben@mrbrklyn.com> - 2015-03-29 03:39 -0400
  Re: what the fork is wrong with strtok_r Lőrinczy Zsigmond <nospam@for.me> - 2015-03-29 08:28 +0200

csiph-web