strtok函数使用参考:
https://blog.csdn.net/weixin_38184741/article/details/88844286
解决连续两个分割符当作一个的参考代码:
int n;
int tmp_len = len;
for(n=0; n<tmp_len; n++) //解决:strtok两个连续分隔符当作一个提取的问题
{
if(tmp_buf[0] == ';') //第一个字符就是分隔符
{
tmp_len++;
int i;
for(i=tmp_len; i>0; i--)
{
tmp_buf[i] = tmp_buf[i-1];
}
tmp_buf[0] = ' ';
}
if((tmp_buf[n] == ';') && (tmp_buf[n+1] == ';'))
{
tmp_len++;
int i;
for(i=tmp_len; i>n; i--)
{
tmp_buf[i] = tmp_buf[i-1];
}
tmp_buf[n+1] = ' ';
}
}
char *result = NULL;
int index = 0 ;
result = strtok( tmp_buf, ";" );
while( result != NULL )
{
switch(index)
{
case 0:
{
break;
}
case 1:
{
break;
}
case 2:
{
break;
}
default :
{
break;
}
result = strtok( NULL, ";" );
index++;
}
}