Click here to Skip to main content
15,671,149 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need a way to split a char * over the symbol "->"

Example : abc->efg

has to be split to "abc" and "efg"

tried using strtok but the problem is that it considers "->" to be two different symbols and cause problems in cases like :

ideally the split should result in two strings "abc-efg" and "hyj"
strtok gives three "abc" "efg" and "hyj"

Any suggestions
satrio_budidharmawan 30-Apr-12 23:41pm    
Hei, the result of this : abc-efg->hyj
should be : "abc" "efg" ">hyj"
Not abc" "efg" and "hyj"

1 solution

That is because strtok matches any of the characters as delimiters, rather than all of them:[^]

Have a look at strstr instead:[^] - you will have to call it repeatedly, but it will do what you want.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900