tags:

views:

47

answers:

2

I am using the following code to tokenize the string in C and using " ," to make tokens but i wanted to know when it make token of string when " " came and when "," occur in the string.

char *pch;
      pch = strtok(buffer, ", ");
      while (pch!=NULL) {
       printf("%s\n", pch);
       pch = strtok(NULL, " ,");
      }
+2  A: 

As far as I know, strtok does not support that feature. However, you may do additional check: whenever pch is returned, see whether the first character of the remaining buffer has " " or ",". Then, you need to track down the remaining buffer, but this is your homework :)

minjang
A: 

The strtok and the CLIB does not expose this information. So there is no portable way to get it.

You may get the information you're looking for with a hack that works for your clib-implementation, but if you want something stable and portable the only choice you have is to implement a strtok-workalike that tells you the separator.

That task is not rocket-science btw...

Nils Pipenbrinck