我像这样使用 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/