简体   繁体   English

Delim可以在C中的strtok中多次使用吗?

[英]Can a delim be used more than once for strtok in C?

Is there a way to use a delim more then once for strtok? 有没有一种方法可以使用delim然后再一次使用strtok? I can only get the code to work for either load or init but not both. 我只能使代码可用于加载或初始化,但不能同时用于两者。 Example code in which strtok is used to token input from the user in the form of load # or init #,#,direction: 示例代码,其中strtok用于标记用户以load#或init#,#,direction的形式输入的代码:

if ((tok = strtok(choice, " ")) && strcmp(tok, COMMAND_LOAD) == 0){
    tok = NULL;
    if((tok = strtok(tok, " ")) != NULL){
    /*some code*/
    }
}
else if((tok = strtok(choice, " ")) && strcmp(tok, COMMAND_INIT) == 0){
    tok = NULL;
    if((tok = strtok(tok, ",")) != NULL){
    /*some code*/
    }
}

The strtok function is not reentrant, you can not use it for multiple simultaneously tokenizations. strtok函数不可重入,不能将其用于多个同时标记化。

Use strtok_s instead, if you have it. 如果有,请改用strtok_s Or strtok_r is you have it. 还是strtok_r ,您拥有它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM