strsep 库函数用于分解字符串。通常用于URL解析。
- #include <stdio.h>
-
#include <string.h>
-
-
char *strsep_test(char **s, const char *ct);
-
-
int
-
main(int argc, char **argv)
-
{
-
char s[] = "";
-
char *ss = s;
-
char *t = "/";
-
-
printf("Result: %s\n", strsep_test(&ss, t));
-
-
return 0;
-
}
-
-
char*
-
strsep_test(char **s, const char *ct)
-
{
-
char *sbegin = *s;
-
char *end;
-
-
if (sbegin == NULL) {
-
return NULL;
-
}
-
-
end = strpbrk(sbegin, ct);
-
if (end) {
-
*end++ = '\0';
-
}
-
*s = end;
-
-
return sbegin;
-
}
注:char **
阅读(374) | 评论(0) | 转发(0) |