As was sayed replace :
Code:
void ptr_explode(char *ptr, char **results)
with
Code:
void ptr_explode(char *ptr, char results[][256])
and replace
with
It is alway a good idea to remove variables you don't use.
like aux.
The all code. should look like this :
Code:
void ptr_explode(char *ptr, char results[][256], int *pntokens)
{
char *result;
char string[strlen(ptr)];
strcpy(string, ptr);
*pntokens = 0;
result = strtok(string, " ");
while (result != NULL) {
strcpy(results[(*pntokens)++], result);
result = strtok(NULL, " ");
}
}
int main(void)
{
char *ptr = "a pointer with a buch of words un fun funf un";
char words[256][256];
int aux;
int ntokens = 0;
ptr_explode(ptr, words, &ntokens);
for(aux=0 ; aux < ntokens ; aux++)
puts(words[aux]);
getche();
return 0;
}