Last active
August 29, 2015 14:02
-
-
Save brendanashworth/d9f6c48406865ab037d8 to your computer and use it in GitHub Desktop.
Split a string by a delimiter into a string array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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