Link to home
Start Free TrialLog in
Avatar of eoincorrigan
eoincorrigan

asked on

strtok Problem


On the first call to strtok, the function skips leading delimiters and returns a pointer to the first token in the string.  Then it puts a NULL in and carries on from where it left off.

Using the this string with delimiters is fine…

WHITE|GREEN|BLUE|YELLOW|ORANGE|PINK|RED|BLACK

I get all the tokens out in order as expected.  However I have to deal with situations where some of the fields are blank, so there will be two fence characters side by side.  And I want to know which fields are empty.

So with a string like this…

|GREEN||YELLOW|ORANGE|PINK||BLACK

I want to get this result…

Field 1:
Field 2: GREEN
Field 3:
Field 4: YELLOW
Field 5: ORANGE
Field 6: PINK
Field 7:
Field 8: BLACK

I know that my records should have 8 fields each.  But I need to know which are empty, even the ones at the start and the end.
ASKER CERTIFIED SOLUTION
Avatar of jhance
jhance

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial