strtok behavior

前端 未结 2 599
清酒与你
清酒与你 2021-01-21 15:44
 int main ()
 {

    char str[] =\"kk,12,,23,4,,,3434,3,33,,,\";
    char * valarr;
    int count=0;
    valarr = strtok(str,\",\"); 
    while(valarr != \'\\0\')
    {
         


        
相关标签:
2条回答
  • 2021-01-21 15:56

    Correct. The documentation states this pretty clearly:

    A sequence of two or more contiguous delimiter characters in the parsed string is considered to be a single delimiter.

    That's just how strtok() is supposed to work. You might be better of rolling your own, which will also free you from strtok()'s nastiness.

    0 讨论(0)
  • 2021-01-21 16:17

    Short answer: NO At least using strtok, check this to learn what's better for your application.

    0 讨论(0)
提交回复
热议问题