Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char **strToWordArray(char *str, const char *delimiter)
- {
- char **words;
- int nwords = 1;
- words = malloc(sizeof(*words) * (nwords + 1));
- int w = 0;
- int len = strlen(delimiter);
- words[w++] = str;
- while (*str)
- {
- if (strncmp(str, delimiter, len) == 0)
- {
- for (int i = 0; i < len; i++)
- {
- *(str++) = 0;
- }
- if (*str != 0) {
- nwords++;
- char **tmp = realloc(words, sizeof(*words) * (nwords + 1));
- words = tmp;
- words[w++] = str;
- } else {
- str--;
- }
- }
- str++;
- }
- words[w] = NULL;
- return words;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement