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;
}
阅读(2232) | 评论(1) | 转发(0) |