1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#include <stdio.h> char *strsep(char **stringp, const char *delim) { char *s, *tok; const char *spanp; int c, sc; s = *stringp; if (!s) return NULL; tok = s; do { c = *s++; spanp = delim; do { sc = *spanp++; if (sc == c) { if (c == 0) s = NULL; else s[-1] = 0; *stringp = s; return tok; } } while (sc != 0); } while (1); }