#define MAX_LEN 64
/*
函 数:SplitString
功 能:将一串字符分割为几个单词
参 数:string-被拆分字符串; res-保存拆分后的单词
返回值:单词个数
*/
int SplitString(char *string, char *res[])
{
static char str[MAX_LEN];
strcpy(str, string);
int count = 0;
char *temp = NULL;
char delims[] = " "; // 按空格拆分
temp = strtok(str, delims);
res[count] = temp;
while (temp != NULL)
{
temp = strtok(NULL, delims);
res[++count] = temp;
}
return count;
}
C语言字符串拆分
最新推荐文章于 2025-03-08 10:28:00 发布