小编Phu*_*e 2的帖子

使用strtok_r时出现分段错误

任何人都可以解释为什么我在下面的例子中得到分段错误?

#include <stdio.h>
#include <string.h>

int main(void) {
  char *hello = "Hello World, Let me live.";
  char *tokens[50];
  strtok_r(hello, " ,", tokens);
  int i = 0;
  while(i < 5) {
    printf("%s\n", tokens[i++]);
  }
}
Run Code Online (Sandbox Code Playgroud)

c strtok segmentation-fault

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

标签 统计

c ×1

segmentation-fault ×1

strtok ×1