首页 > 代码库 > 字符分割函数
字符分割函数
char *strsep(char **stringp, const char *delim){ char *s; const char *spanp; int c, sc; char *tok; if ((s = *stringp)== NULL) return (NULL); for (tok = s;;)
{ c = *s++; spanp = delim; do
{ if ((sc =*spanp++) == c)
{ if (c == 0) s = NULL; else s[-1] = 0; *stringp = s; return (tok); } } while (sc != 0); }}
测试:
int main (void){ char *pString = "1234;123.112.123.123:8081;GPSDATA;;60;19200;8;N;1;N"; char *pStrTmp[20]={NULL}; int i=0; pStrTmp[i] = strsep(&pString,";"); while((pStrTmp[i] != NULL)&&(i<19))
{ i++; pStrTmp[i] = strsep(&pString,";"); printf("pStrTmp[%d] = %s\n",pStrTmp[i] ); } return 0;
}
运行结果:pStrTmp[0] = "1234";pStrTmp[1] = "123.112.123.123:8081";pStrTmp[2] = "GPSDATA";pStrTmp[3] = "";pStrTmp[4] = "60";pStrTmp[5] = "19200";pStrTmp[6] = "8";pStrTmp[7] = "N";pStrTmp[8] = "1";pStrTmp[9] = "N";
字符分割函数
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。