分类: C/C++
2014-04-20 11:10:14
char* my_strtok(char *s, const char *delim) { static int flags[256]; static char *orig_s = NULL; static const char *orig_delim = NULL; char *p; if (NULL == delim) return s ? s : orig_s; if (delim != orig_delim) { orig_delim = delim; memset(flags, 0, sizeof(flags)); while (*delim) flags[(int)*delim++] = 1; } if (s) orig_s = s; if ((!orig_s) || (!*orig_s)) return NULL; while (flags[(int)*orig_s]) ++orig_s; p = orig_s; while (!flags[(int)*orig_s]) ++orig_s; *orig_s++ = 0; return p; }