Why should strtok() be deprecated?

后端 未结 2 1433
心在旅途
心在旅途 2021-01-01 18:26

I hear this from a lot of programmers that the use of strtok maybe deprecated in near future. Some say it is still. Why is it a bad choice? strtok() works great in tokenizin

2条回答
  •  猫巷女王i
    2021-01-01 19:07

    The limitation of strtok(char *str, const char *delim) is that it can't work on multiple strings simultaneously as it maintains a static pointer to store the index till it has parsed (hence sufficient if playing with only one string at a time). The better and safer method is to use strtok_r(char *str, const char *delim, char **saveptr) which explicitly takes a third pointer to save the parsed index.

提交回复
热议问题