Possible Duplicate:
Split string with delimiters in C
I’m searching a good way to “explode” a char* into other char* using a delimiter.
My delimiter will be #
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use
strtoklike CrazyCasta said but his/hers code is wrong.Be aware that
strtokhas to be called the first time with the source pointer, after that you have to useNULL. Alsosrcmust be writeable becausestrtokwrites\0to terminate the found strings. Hence, depending on how you read the string (and whether you are going to use it afterwards or not), you should do a copy of it. But as I said, this is not always necessary.EDIT:
an
explodefunction could look like this:then you have to call it:
this is an example running with valgrind: