C 分割字符串函数

来源:百度知道 编辑:UC知道 时间:2024/06/28 06:15:37
求高手写个C语言的分割字符串函数

例如:A1:B1:C1,A2:B2:C2,A3:B3:C3
第一次以逗号为分割符号分割,再以冒号为分割号分割
得到的3组字符串存到结构中
2L,感谢你的回答,你这个方法我也试过,但是我还要根据得到的字符串做判断,
比如说要根据得到的每一组的第一字符串来做判断
而且strtok不能得到空值

去C语言帝国问问吧

http://www.vcgood.com/

Download: strtok_sample.c#include <stdio.h>
#include <string.h>
int main(int argc,char **argv)
{
char * buf1="aaa, ,a, ,,,bbb-c,,,ee|abc";
/* Establish string and get the first token: */
char* token = strtok( buf1, ",-|");
while( token != NULL )
{
/* While there are tokens in "string" */
printf( "%s ", token );
/* Get next token: */
token = strtok( NULL, ",-|");
}
return 0;
}