【发布时间】:2018-11-15 00:58:33
【问题描述】:
#include <stdio.h>
#include <string.h>
int main(){
char name[] = "eseumdesconhecidolheoferecerflores.issoeimpulse.cities";
char *str;
printf("%s\n", name)
str = strtok(name, ".cities");
printf("%s\n", str);
return 0;
}
这是输出:
eseumdesconhecidolheoferecerflores.issoeimpulse.cities
umd
我完全不知道发生了什么。我想要的是 strtok 的输出是指向"eseumdesconhecidolheoferecerflores.issoeimpulse"的指针
【问题讨论】:
-
在回答显而易见的问题之前(这就是
strtok的工作原理)read the documentation of the function,然后解释一下你期望输出应该是什么以及为什么你会这样想了解该功能的工作原理(假设您实际阅读了我链接的内容) -
如果你只是想剥离 .cities 那么不要使用 strtok,它的杀伤力太大了。