/* lib/string.c */
strsep函数用于分割字符串,函数原型如下:
char *strsep(char **s, const char *ct);
s为指向欲分割的字符串,ct为分隔符,函数将返回分隔符前面的字符串,s将指向分隔符之后的字符串,实例如下:
#include <stdio.h>
#include <string.h>
int main(void)
{
char s[] = "hello world!";
char *p = s;
char *d = " ";
printf("%s\n", strsep(&p, d));
printf("%s\n", p);
return 0;
}
函数打印如下:
hello
world!
该函数同strtok函数类似,用来替换strtok函数的,原因如下:
* - Added strsep() which will replace strtok() soon (because strsep() is
* reentrant and should be faster). Use only strsep() in new code, please.