char *strsplit(const char *str, char splitchar, int token_num) { char *start = str; char *end; while(token_num && *start != '\0') { if(*start == splitchar) token_num--; start++; } end = start; while(*end != '\0' && *end != splitchar) end++; posix_strncpy(tmpbuf, start, end - start - 1); return tmpbuf; }