I have a tokenizer method that returns a char**
. The results are being stored in a char**
called lineTokens
. When I use printf()
to print the first token, I get the correct result, but when I use strcmp(lineTokens[0],"Some text")
, I get a seg fault. The appropriate code is below.
lineTokens = tokenize(tempString);
printf("token[0] = %s\n", lineTokens[0]);
if(strcmp(lineTokens[0], "INPUTVAR")==0){
printf("It worked\n");
}
EDIT: My tokenize code is as follows
char** tokenize(char* input){
int i = 0;
char* tok;
char** ret;
tok = strtok(input, " ");
ret[0] = tok;
while(tok != NULL){
printf("%s\n", tok);
ret[i] = tok;
tok = strtok(NULL, " ");
i++;
}
ret[i] = NULL;
return ret;
}