strtok skips 1s

Hello everyone. I have an odd problem. I am using strtok to parse a comma separated string. It looks something like the following: “1,3,4132”. Right now, I am just trying to grab the first two numbers and set them as the type and version. The problem arises out of the fact that strtok appears to be completely skipping the 1s. My type gets set to “3” and my version gets set to “4”.

When I use something like “2,3,456” it works just fine and my type is “2” my version is “3”. If I use “2,1,456” my type is “2” but my version is “456”.

Does anyone have any idea what might be happening?

Thanks in advance for any comments!

How did you define the separator char, exactly? Take care it is not taking “1” as separator, also, accidentally…

Actually, strtok takes a null terminated array of delimiters.

Try;

char delimiters[2];

strcpy(delimiters, “,”);

I guess that could happen. strtok takes an array of delimiters so I set it up like the following:

char delimiters[1];

delimiters[0] = ‘,’;

Eventually, I just wrote my own function to tokenize the buffer and it works very well. It uses pointers :smiley: