Troubles passing 2D arrays of char
well, take a little look in it:
Code:
#include <stdio.h>
#include <string.h>
void ptr_explode(char *ptr, char *results)
{
//char *ptr = "a pointer with a buch of words un fun funf unf ";
/* first 'convert' the pointer into a string so that we can use strtok */
int ptrlen = strlen(ptr);
char string[ptrlen];
strcpy(string, ptr);
char *result = NULL;
int ntokens = 0, aux;
char words[256][256];
result = strtok(string, " ");
while (result != NULL) {
strcpy(words[ntokens++], result);
result = strtok(NULL, " ");
}
for(aux=0;aux<=ntokens;aux++){
strcpy(results, words[aux]);
}
}
int main(void)
{
char *ptr = "a pointer with a buch of words un fun funf un";
char *exploded;
char words[256][256];
int aux, aux1;
for(aux=0;aux<=256;aux++){
for(aux1=0;aux1<=256;aux1++){
words[aux][aux1]='\0';
}
}
ptr_explode(ptr, words);
return 0;
}
i'm very dizzy with all of this, plz someone tell me what i did wrong!