小编it-*_*son的帖子

strtok c 多个字符作为一个分隔符

是否可以使用多个字符作为一个分隔符?

我想要一个字符串作为另一个字符串的分隔符。

char * input = "inputvalue1SEPARATORSTRINGinputvalue2SEPARATORSTRINGinputvalue2";
char * output = malloc(sizeof(char*));
char * delim = "SEPARATORSTRING";

char * example()
{
    char * ptr = strtok(input, delim);

    while (ptr != NULL)
    {
      output = strcat(output, ptrvar);
      output = strcat(output, "\n");
      ptr = strtok(NULL, delim);
    }

    return output;
}
Run Code Online (Sandbox Code Playgroud)

返回值打印为printf

inputvalue1
inputvalue2
inputvalue3
Run Code Online (Sandbox Code Playgroud)

c delimiter strtok

3
推荐指数
1
解决办法
125
查看次数

标签 统计

c ×1

delimiter ×1

strtok ×1