strtok strtok_r
分解字符串为一组字符串。s为要分解的字符串,delim为分隔符字符串。首次调用时,s指向要分解的字符串,之后再次调用要把s设成NULL。
#include<string.h>
#include<stdio.h>
intmain(
void
)
{
charinput[16]=
"abc,d"
;
char
*p;
/**/
/*strtokplacesaNULLterminator
infrontofthetoken,iffound*/
p=
strtok
(input,
","
);
if
(p)
printf
(
"%s\n"
,p);
/**/
/*AsecondcalltostrtokusingaNULL
asthefirstparameterreturnsapointer
tothecharacterfollowingthetoken*/
p=
strtok
(NULL,
","
);
if
(p)
printf
(
"%s\n"
,p);
return0;
}
strtok_r