http://blog.sina.com.cn/s/blog_7ee076050102vamg.html
http://www.cnblogs.com/lixiaohui-ambition/archive/2012/07/18/2598042.html
int in=0; int j; char buffer[100]="Fred male 25,John male 62,Anna female 16"; //char buffer[100]="Fred male 25";
char *p[20]; char *buf = buffer; while((p[in]=(char *)strtok(buf,","))!=NULL) { buf=p[in]; while((p[in]=(char *)strtok(buf," "))!=NULL) {
in++; buf=NULL;
} buf=NULL;
} lr_output_message("总共分割成:%d个字符串", in); for (j=0; j<in; j++) { lr_output_message(">%s<",p[j]); }
#include <stdio.h>
#include <string.h>
int main(int argc,char **argv)
{
char buf1[]="aaa,
,a,,,,bbb-c, , ,ee|abc";//必须为[],即字符串为有名字符串,而非匿名字符串 char* token = strtok( buf1, ",-|
");
while( token != NULL )
{
printf("%s", token
);
token = strtok( NULL, ",-|");
}
printf("\n");
return 0;
}
OUT 值:
aaa abbbc eeabc