# 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]`是存在棧上,是可以隨意改寫的。