Split string with dash delimiters and more

I have implemented strtok and strtok_r with much ease recently. But I have encountered a strange problem. My sentence is something like this without the quotes: "now- the-boy is- going". The program works but only prints the word "now". I have noticed that if I close the spaces the entire sentence prints which I understand to be from the condition "while var!=NULL". But I need the spaces to remain so that at the end the program prints:"now the boy is going". How do I deal with this.

Thank you.

The program works

What program would that be ?

You now that the strtok() and strtok_r() functions are already present in arduino?
If you want help with your code you will have to post it (in code brackets)

Keep in mind that strtok() overwrites the delimiter with the null termination character when it finds a match. It then increments the internal pointer so it looks past the null on the next iteration. This is why only the first call passes the starting address of the object being searched and all others are null.

Apologies for turning up late. OK here is my code below. buf receives the chinese strings with dash delimiters and spaces. After the dash delimiter has been stripped, the chinese character is compared to the chinese array. if a match is found it simply prints out the english equivalent since the english array is the same size with the chinese array. I have tried to change the code below in different ways but I cant seem to figure out how to go about it.

             char english[] = {'A','B'.......'Z'};
                      char chinese[] ={'x','xi'.......'yu'};// just an example 
                       p = strtok(buf, "-");  //buf contains chinese string with dashes.

                       for (int i = 0; i < sizeof(chinese)/sizeof(chinese);i++){ 
                             p = strtok(NULL, "-");      
for (int i = 0; i < sizeof(chinese)/sizeof(chinese);i++)

sizeof(chinese)/sizeof(chinese) will always equal 1

Did you perhaps mean

  1. I am pretty sure that sizeof(chinese)/sizeof(chinese) is going to equal 1, so you will only check one character.

  2. 'xi' is not a character, it is two characters, so it cannot fit into a char.

  3. I am pretty sure that your array definition will not create the '\0' terminated char array that strtok() expects.

Thank you UKhelibob. Those are just typo errors I did when i posted my response, sorry about that. @KeithRB i disagree with you somewhat. the xi prints out just fine if its put as the first character.

Once again the code I have posted only prints a single character. It only prints everything if i close the spaces. It seems something wrong happens if it encounters a space.

What do you mean by "close the spaces"?

Can you copy and paste the correct code? why should we get worked up over typos?

hose are just typo errors I did when i posted my response,

Why are you typing any code in here ? What is the point of posting code that is not the same as what you have in the IDE ? If you are going to type it in here then all bets are off as to what you are actually trying to compile and run.