Do I need to free the strtok resulting string?

前端 未结 3 1368
遇见更好的自我
遇见更好的自我 2021-01-01 15:30

Or rather, how does strtok produce the string to which it\'s return value points? Does it allocate memory dynamically? I am asking because I am not sure if I need to free th

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-01 16:15

    According to the docs:

    Return Value

    A pointer to the last token found in string.

    Since the return pointer just points to one of the bytes in your input string where the token starts, whether you need to free depends on whether you allocated the input string or not.

提交回复
热议问题