i got a problem with my C code.

```
int split(char* source, char*** target, char* splitChar) {
    int i;
    int currentLength;
    int splitCharPosition;
    char* currentSubstring = source;
    int splitCount = charcount(source, splitChar) + 1;

    *target = (char**) malloc(splitCount * sizeof(char**));
    for(i=0;i<splitCount;i++) {
        splitCharPosition = indexOf(currentSubstring, splitChar);
        substring(currentSubstring, target[i], 0, splitCharPosition);
        currentLength = strlen(currentSubstring);
        substring(currentSubstring, &currentSubstring, splitCharPosition + 1, curr  entLength-splitCharPosition);
    }
    return splitCount;
}

```

The problem is that if I use the Debugger, the pointer to splitChar is set to 0x0 after the first run of the for loop.
Does anybody know why it is set to 0x0?

EDIT:

```
int indexOf(char* source, char* template) {
int i;
int j;
int index;
for (i = 0; source[i]; i++) {
    index = i;
    for (j = 0; template[j]; j++) {
        if (source[i + j] != template[j]) {
            index = -1;
            break;
        }
    }
    if (index != -1) {
        return index;
    }
}
return -1;
}

```

EDIT2:

```
int charcount(char* source, const char* countChar) {
int i;
int count = 0;
for(i=0;source[i];i++) {
    if(source[i] == countChar[0]) {
        count++;
    }
}
return count;
}

```

EDIT3:

```
char* substring(char* source, char** target, int start, int length) {
    *target = (char*) malloc(length + 1);
    strncpy(*target, source + start, length);
    target[length] = '\0';
    return *target;
}

```

EDIT4:
I just noticed that if I add

```
char* sndfpgjps = splitChar;

```

to my split() code it does not delete the reference. Anyone know why?