c - strtok_r - 在分隔符之间没有任何内容时得到指示

标签 c unix

我像这样使用 strtok_r:

char *the_sting = "a|b||e|f";
char *last;
char *current;

current = (char*)strtok_r(the_sting, "|", &last);

while(current != NULL)
{
    printf(current);
    printf("\n");
    current = (char*)strtok_r(NULL, "|", &last);
}

我得到:

>>a
>>b
>>e
>>f

问题是,当分隔符之间没有任何内容时,我需要“空白”。

喜欢:

>>a
>>b
>>
>>e
>>f

最佳答案

比较当前的current和之前的current。如果差异大于 strlen(previous_current) + 1,则跳过一个或多个空位。

关于c - strtok_r - 在分隔符之间没有任何内容时得到指示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16712498/

相关文章:

c++ - 帮助在 C++ 中声明和使用动态分配的数组

linux - 为什么 Unix "strings"命令删除 XML 注释关闭标记?

linux - 结合linux中的ionice和nice,以及传递优先级

linux - Bash:如何让脚本作为后台任务重新运行?

linux - Perl:循环运行另一个系统命令时在后台尾部文件

bash - 有没有办法让任务栏从终端闪烁?

c++ - 是否可以修改内存中的函数?

c - 将 rand() 的输出放入数组

创建一个程序来求解幂而不使用 pow() 而使用 While 循环 : PROBLEM WITH "UNDEFINED" ANSWRES

c - 如何在c中找到数组中最大和最小的数字