#include<stdio.h> #include<string.h> int main() { char *s="annfyjhskdfyioioofypokkfykkkkkkfyiiii"; char *delim="fy"; char *p; printf("%s\n",strtok(s,delim)); while( p=strtok(NULL,delim)) printf("%s\n",p); return 0; }
为什么运行总是出现。。。。。。段错误。。。。呢
char s[]="annfyjhskdfyioioofypokkfykkkkkkfyiiii";
改成这个就ok了
the first
* call, with string specified, returns a pointer to the first char of the
* first token, and will write a null char into string immediately
* following the returned token.
你的程序中s指向一个常量区,无法修改!