nc.*_*nc. 6 c strtok bus-error
我认为这是第一次失败的召唤.我写了C已经有一段时间了,我不知所措.非常感谢.
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv) {
char *str = "one|two|three";
char *tok = strtok(str, "|");
while (tok != NULL) {
printf("%s\n", tok);
tok = strtok(NULL, "|");
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
字符串文字应该分配给const char*,因为修改它们是未定义的行为.我很确定strtok修改了它的参数,这可以解释你看到的坏事.