How to use Strtok for tokenizing a Const char*?

◇◆丶佛笑我妖孽 提交于 2019-12-03 05:00:58

Since strtok actually writes to your string, you need to make a writable copy of it to tokenize;

char* copy = strdup(myReadonlyString);
...tokenize copy...
free(copy);

Declare it as an array:

char tokenedStr[] = "OpenStack:OpenStack1";

if not possible, copy it to a char array.

You can make a copy of your non-modifiable string and then use strtok.

You can portably use malloc and strcpy to copy the string.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!