#include<stdio.h> char *strsep(char **stringp, const char *delim) { char *s; const char *spanp; int c, sc; char *tok; if ((s = *stringp)== NULL) return (NULL); for (tok = s;;) { c = *s++; spanp = delim; do { if ((sc =*spanp++) == c) { if (c == 0) s = NULL; else s[-1] = 0; *stringp = s; return (tok); } } while (sc != 0); } /* NOTREACHED */ } int main() { char *s3; char s1[] = "h,e,l,l,o,word"; char *s2 = ","; char *buf; buf = s1; while((s3 = strsep(&buf,s2)) != NULL) { printf("%s\n",s3); } return 0; } 运行结果: h e l l o word
原文:http://www.cnblogs.com/51CC-YL/p/7360363.html