Skip to content

Instantly share code, notes, and snippets.

@brendanashworth
Last active August 29, 2015 14:02
Show Gist options
  • Save brendanashworth/d9f6c48406865ab037d8 to your computer and use it in GitHub Desktop.
Save brendanashworth/d9f6c48406865ab037d8 to your computer and use it in GitHub Desktop.
Split a string by a delimiter into a string array
// NOTE: This gist requires https://gist.github.com/boboman13/956405a90345f3ce477c.
char **str_split(char *string, char *delim) {
uint8_t size = str_count(string, "") + 1, i;
char** split = malloc(size * sizeof(char*) );
for (i = 0; i < size; i++) {
if (i == 0)
split[i] = strtok(string, delim);
else
split[i] = strtok(NULL, delim);
}
return split;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment