#include <stdio.h>
#include <string.h>
void mySplit(char *src,const char *separator, char dest[][20], int *num)
{
char *pPre = NULL;
char *pNext = NULL;
//记录分隔符数量
int count = 0;
//原字符串为空
if (src == NULL || strlen(src) == 0)
return;
//未输入分隔符
if (separator == NULL || strlen(separator) == 0)
return;
//获得第一个由分隔符分割的字符串
pNext = strtok(src,separator);
while(pNext != NULL) {
//存入到目的字符串数组中
pPre = pNext;
pNext = strtok(NULL, separator);
if (pPre && pNext)
{
rt_strncpy(dest[count++], pPre, (pNext-pPre-1));
}
else if(pPre)
{
strcpy(dest[count++], pPre);
}
}
*num = count;
}
标签:count,函数,C语言,char,separator,split,pPre,NULL,pNext
From: https://www.cnblogs.com/HuangLiDi/p/18131520