Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1990204
  • 博文数量: 433
  • 博客积分: 918
  • 博客等级: 准尉
  • 技术积分: 3218
  • 用 户 组: 普通用户
  • 注册时间: 2012-02-24 18:21
个人简介

你是不是暗恋我,那就给我发个消息呀,让我知道o(∩∩)o

文章分类

全部博文(433)

分类: LINUX

2013-01-07 20:43:35

strtok()函数的第一个参数不能是char *型的,因为会段错误


#include
#include
int main(void)
{
char *input= "wo:you:content",out[16];
char *p,*q,*con,*p1,*q1,*con1;
/**/ /* strtok places a NULL terminator
in front of the token, if found */
sprintf(out,"%s","sdfg:sdfk:jdg");
p1 = strtok(out, ":");
q1 = strtok(NULL, ":");
con1=strtok(NULL, ":");

//if (q) printf("%s\n", q);

if (p1&&q1&&con1) printf("%s\n%s\n%s\n", p1,q1,con1);

p = strtok(input, ":");
//if (p) printf("%s\n", p);
/**/ /* A second call to strtok using a NULL
as the first parameter returns a pointer
to the character following the token */
q = strtok(NULL, ":");
con=strtok(NULL, ":");
if (p&&q&&con) printf("%s\n%s\n%s\n", p,q,con);

return 0;
}
阅读(2175) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

Bean_lee2013-01-09 13:00:40

不要用这个函数,改用这个strtok_r