Re: strtok question
- From: jt@xxxxxxxxxxx (Jens Thoms Toerring)
- Date: 31 May 2008 15:44:54 GMT
Stu Cazzo <SCazzo@xxxxxxxxx> wrote:
Hi all,
I have a question on why strtok is doing what it's doing for my
splitString( string2 ); call.
Below is the output for the entire program:
token was: word1
token was: word2
token was: word3
token was: word1
token was: word3
empty field found - token <(null)>
The splitString( string1 ); works as expected, 3 tokens are found.
The splitString( string2 ); does not work as I expected.
I was expecting this:
token was: word1
empty field found - token <(null)>
token was: word3
Why does it not see the empty field for lineToken2?
Because that's not how strtok() works. The man page on my machine
for strtok() actually makes it rather clear:
A sequence of two or more contiguous delimiter characters in the
parsed string is considered to be a single delimiter. Delimiter
characters at the start or end of the string are ignored. Put
another way: the tokens returned by strtok() are always non-empty
strings.
So if you have more than one ',' in a row all of them are treated
the same as a single ','.
Is there a better way to strip out the tokens for the case I have
where there is no space between my delimiter?
I guess you will have to write your own function for that, probably
repeatedly using strchr() or strstr().
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@xxxxxxxxxxx
\__________________________ http://toerring.de
.
- Follow-Ups:
- Re: strtok question
- From: CBFalconer
- Re: strtok question
- References:
- strtok question
- From: Stu Cazzo
- strtok question
- Prev by Date: struct padding ???
- Next by Date: Re: struct padding ???
- Previous by thread: strtok question
- Next by thread: Re: strtok question
- Index(es):
Relevant Pages
|