You can initialize the output with a default capacity, then when need, you can reallocate the memory as need
Some thing like
char** parse(char* input) {
char* str = strdup(input);
int count = 0;
int capacity = 10;
char** result = malloc(capacity * sizeof(char*));
char* tok = strtok(str," ");
while(tok != NULL){
if (count >= capacity) {
capcity = 2 * capacity; // or grow it the way as you need
result = realloc(result, capacity * sizeof(char*));
}
result[count++] = strdup(tok);
tok=strtok(NULL," ");
}
free(str);
return result;
}
Just the idea, hope it helps