相关疑难解决方法(0)

为什么strtok会改变这样的输入?

好的,所以我理解strtok会修改它的输入参数,但在这种情况下,它会将输入字符串折叠成只有第一个标记.为什么会发生这种情况,我该怎么做才能解决这个问题?(请注意,我不是在谈论变量"temp",它应该是第一个令牌,而是变量"input",在一次调用strtok后变为"this")

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

int main(int argc, char* argv[]) {
   char input[]="this is a test of the tokenizor seven";
   char * temp;
   temp=strtok(input," ");
   printf("input: %s\n", input); //input is now just "this"
}
Run Code Online (Sandbox Code Playgroud)

c strtok

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

标签 统计

c ×1

strtok ×1