char *strsplit(const char *str, char splitchar, int token_num)
{
//if (token_num >= strnumtokens(str, splitchar))
// printf("1");
// return NULL;
// copy the string so we can change it if we want
// lib/string.c:128: warning: initialization discards qualifiers from pointer target type - no idea how to fix that.
char *string = str;
int i;
// find the start of the token
for (i = 0; i < token_num; i++)
{
// using string += ... doesn't seem to work here.
int j;
// don't put this in the for loop...
int k = strchr(string, splitchar);
for (j = 0; j <= k; j++)
string++;
}
// put a \0 on the end of that token
string[strchr(string, splitchar)] = '\0';
return string;
}