C语言有没有把字符串拆分为数组的函数?

如题所述

用strtok函数实现吧。
void split( char **arr, char *str, const char *del)//字符分割函数的简单定义和实现
{
char *s =NULL;

s=strtok(str,del);
while(s != NULL)
{
*arr++ = s;
s = strtok(NULL,del);
}
}

int main()
{
int i;
char *myArray[4];
char s[] = "张三$|男$|济南$|大专学历$|";

memset(myArray, 0x0, sizeof(myArray));
split(myArray, s, "$|");

for (i=0; i<4; i++)
{
printf("%s\n", myArray[i]);
}
return 0;
}
温馨提示:答案为网友推荐,仅供参考