小编Tec*_*eek的帖子

为什么我的将字符串拆分为标记的 C 程序不打印任何内容

我有 C 代码,用于使用该strtok()函数将示例字符串拆分为标记。我似乎已经遵循了书中的所有内容,但我的 CLion 编译器不会打印各个字符串标记并使用此代码退出脚本Process finished with exit code -1073741819 (0xC0000005)。下面是我尝试分割字符串的方法,帮助我调试问题。

//declare and assign the sentence I need to split
char * sentence ="Cat,Dog,Lion";
//declare and assign the delimiter 
char * delim=",";
//get the first token
char * token = strtok(sentence, delim);
while(token!= NULL){
     //print a single string token
      printf("%s",token);
      //reset the loop for the iteration to continue
      token = strtok(NULL,delim);
    }
Run Code Online (Sandbox Code Playgroud)

c strtok

0
推荐指数
1
解决办法
100
查看次数

标签 统计

c ×1

strtok ×1