首页 新闻 赞助 找找看

请求strtok函数的问题----------------有空的朋友帮帮忙

0
悬赏园豆:5 [已解决问题] 解决于 2013-04-01 15:54
#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;
}

为什么运行总是出现。。。。。。段错误。。。。呢

lonely-fly的主页 lonely-fly | 初学一级 | 园豆:199
提问于:2013-03-31 15:50
< >
分享
最佳答案
0
char s[]="annfyjhskdfyioioofypokkfykkkkkkfyiiii";

改成这个就ok了

收获园豆:5
灭人沉醉 | 菜鸟二级 |园豆:207 | 2013-04-01 12:29

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指向一个常量区,无法修改!

灭人沉醉 | 园豆:207 (菜鸟二级) | 2013-04-01 12:33
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册