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

前端 未结 6 1160
刺人心
刺人心 2020-12-15 04:45

I\'m trying to use this function in a C program that needs to be able to compile in Linux and Windows. At first I tried using strtok_r, but then when I compiled on windows,

6条回答
  •  孤城傲影
    2020-12-15 05:18

    Just to clarify. strtok is thread safe in Windows. strtok uses a TLS variable to maintain the last pointer for each thread. However, you can not use strtok to interleave access to more than one token string per thread. strtok_r and strtok_s both address this interleaving problem by allowing the user to maintain the context via the third parameter. Hope this helps.

提交回复
热议问题