#include
#include
#include
#include
#include
//char *strsep(char **stringp, const char *delim);
//??????·???×?·???????×é×?·?????
//??stringp???ò?????????ò?ó?¨?è??
//????delim???ò??×?·???????×?·??ó??
//????×?·???????NULL??·???stringp???ò?????·??
//
#if 1
void main()
{
char str[] = "abcdefcghdij";
char *p = str;
char *key_point;
key_point = strsep(&p, "cd");
printf("%s\n",key_point);//ab
key_point = strsep(&p, "cd");
printf("%s\n",key_point);//????·?
key_point = strsep(&p, "cd");
printf("%s\n",key_point);//ef
key_point = strsep(&p, "cd");
printf("%s\n",key_point);//gh
key_point = strsep(&p, "cd");
printf("%s\n",key_point);//ij
}
#endif
#if 1
//????2??·???×?·?????×??á:strsep·???????·????ó??????×?·????????????????????????????????ò·????ó?????à×?·??????ü??????·??????ü×???????×?·????????????????????????é????
/*
*????·???????a,b,c??????Jim,JACK??????·???
*/
void main()
{
char str[] = "Jim=88,Jack=89,Lily=86,Lucy=90,a=1,b=2,c=3,d=4,e=5,f=6,g=7";
char *name, *score,*next,*current;
int i;
current = str;
for(i=0; i<11; i++){
name = strsep(¤t,"=");//×??? = ??·??????ó??current????×????ò?ó??????????????=???ó????×?·?
printf("current = %s\n",current);
printf("name = %s\n",name);
// next = score;
score = strsep(¤t, ",");
printf("score = %s\n",score);
}
}
#endif
#if 3
//??????
//strtok????·¨
void main()
{
char token[] = "abdzxbcdefgch";
printf("%s\n",token);
char *tokenremain = token;
char *tok1 = strtok(tokenremain, "cde");
printf("tok1 = %s\n",tok1); //tok1 = ab
//printf("tokenremain = %s\n",tokenremain);//×???tokenremain?????????ò?ó????????strsep????
tok1 = strtok(NULL,"cde");
printf("tok1 = %s\n",tok1);//tok1 = zxb
// printf("tokenremain = %s\n",tokenremain);
tok1 = strtok(NULL,"cde");
printf("tok1 = %s\n",tok1);//tok1 = fg
return ;
/*
*?ò??:
tok1 = ab
tok1 = zxb
tok1 = fg
???ò????????????????:strtok(tokenremain,"ced"),????"cde"????????????×?·??????ü±???\0
?????????±??×?·???????·???????????????×?·??????????ò?ó??????\0?ó????
????×?·?
×???·?????????????×?????×?·???????????????±???
*/
}
#endif