Skip to content

Instantly share code, notes, and snippets.

@alyx
Created July 16, 2012 00:16
Show Gist options
  • Save alyx/3119347 to your computer and use it in GitHub Desktop.
Save alyx/3119347 to your computer and use it in GitHub Desktop.
CorcString **corcstr_split(CorcString *in, char sep)
{
int i = 0;
char *instr, *ptr, *placeholder;
CorcString **out, *cs;
instr = strdup(in->string);
placeholder = instr;
while (ptr = strchr(placeholder, sep))
{
*ptr = '\0';
out[i] = corcstr(placeholder);
placeholder = ptr+1;
++i;
}
if (placeholder)
{
out[i] = corcstr(placeholder);
out[++i] = NULL;
}
else if (i == 0)
{
free(instr);
return NULL;
}
free(instr);
return out;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment