http://www.opengroup.org/onlinepubs/000095399/functions/strtok.html上的strtok 程序每次都会崩溃..
#include <string.h>
...
char *token;
char *line = "LINE TO BE SEPARATED";
char *search = " ";
/* Token will point to "LINE". */
token = strtok(line, search);
/* Token will point to "TO". */
token = strtok(NULL, search);
Run Code Online (Sandbox Code Playgroud)
如果我使用char数组作为变量'line',它可以工作.即char line [] ="LINE TO BE SEPARATED"有效.
请解释一下.
strtok修改输入字符串line.
char *line = "LINE TO BE SEPARATED";
Run Code Online (Sandbox Code Playgroud)
在这种情况下line指向只读存储器.因此,无法修改.你需要传递char数组strtok.