# strtok 演示
期望的结果是`s`字符串被截断为`12345`:
```c
#include <stdio.h>
#include <string.h>
int main(int argc, char const *argv[])
{
char *s = "123456789";
char *tmp = NULL;
tmp = strtok(s, "6");
printf("%s\n", s);
return 0;
}
```
实际运行的结果为
```javascript
Bus error: 10
```
# 修改下
```c
#include <stdio.h>
#include <string.h>
int main(int argc, char const *argv[])
{
// char *s = "123456789";
char s[10] = "123456789";
char *tmp = NULL;
tmp = strtok(s, "6");
printf("%s\n", s);
return 0;
}
```
结果正常了
```javascript
zhoumengkang@bogon:~/Downloads$ gcc test2.c -o test2
zhoumengkang@bogon:~/Downloads$ ./test2
12345
```
`char *s`是存在只读区(常量区),不能被改写;
`char s[10]`是存在栈上,是可以随意改写的。