开发者

How to find out what was the last reason to tokenize

开发者 https://www.devze.com 2022-12-11 10:49 出处:网络
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 s

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, " ,");
}


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 :)


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...

0

精彩评论

暂无评论...
验证码 换一张
取 消