What's the difference between strtok and strtok_r in C?

后端 未结 4 1888
忘掉有多难
忘掉有多难 2021-02-13 04:29

What\'s the difference between strtok and strtok_r in C and when are we supposed to use which?

4条回答
  •  既然无缘
    2021-02-13 04:57

    strtok save static pointer for reuse in the next time, when you give NULL as the first parameter, so you just can't parse 2 strings in parallel.

    In the strtok_r you give also the pointer, as out parameter (pointer to pointer). so there is no static pointer in the function and you can move from one string to another and back...

提交回复
热议问题