strtok_s behaviour with consecutive delimiters

前端 未结 2 1471
死守一世寂寞
死守一世寂寞 2021-01-14 19:55

I\'m parsing 3 values in parallel which are separated with a specific separator.

token1 = strtok_s(str1, separator, &nextToken1);
token2 = strtok_s(str2,         


        
2条回答
  •  醉话见心
    2021-01-14 20:01

    Unfortunately, strtok() ignores empty tokens. Even though you said you wish to avoid doing that, there is no other way but to parse it yourself, using for example strchr() to find the next delimiter and then copying the token to a temporary variable for processing. This way you can handle empty tokens whichever way you please.

提交回复
热议问题