REIMPLEMENTING SPLIT FUNCTION IN C : How can i rewrite the following code into the one below but be able to can the delimiter on each call to the function. I am trying to split line into an array of char*
CODE 1:
```
char *split(const char *string)
{
        char *words[MAX_LENGTH / 2];

        char *word = (char *)calloc(MAX_WORD, sizeof(char));
        memset(word, ' ', sizeof(char));
        static int index = 0;
        int line_index = 0;
        int word_index =0;

        while (string[line_index] != '\n')
        {
                const char c = string[line_index];
                if (c == ' ')
                {
                        word[word_index+ 1] = '\0';
                        memcpy(words+index,&word,sizeof(word));
                        index+=1;
                        if(word!=NULL)
                        {
                                free(word);
                                char *word = (char *)calloc(MAX_WORD,sizeof(char));
                                memset(word, ' ', sizeof(char));
                        }
                        ++line_index;
                        word_index =0;
                        continue;
                }
                if (c == '\t')
                        continue;
                if (c == '.')
                        continue;
                if (c == ',')
                        continue;

                word[word_index] = c;
                ++word_index;
                ++line_index;
        }

        index =0;
        if(word!=NULL)
        {
                free(word);
        }
        return *words;
}
```

CODE 2:
```
char **split(char *string)
{
        static char *words[MAX_LENGTH / 2];
        static int index = 0;
        // resetting words 
        for (int i = 0; i < sizeof(words) / sizeof(words[0]); i++)
        {
                words[i] = NULL;
        }
        const char *delimiter = " ";
        char *ptr = strtok(string, delimiter);
        while (ptr != NULL)
        {
                words[index] = ptr;
                ptr = strtok(NULL, delimiter);
                ++index;
        }
        index = 0;
        return words;
}

```
However i noticed that the memory of word+index is been reassigned to the same location thereby causing word duplication .
