This is something that should be easy to answer, but itβs harder for me to find the specific correct answer on Google or in K & R. I could completely forget about it, and if so, please configure me directly!
The corresponding code is given below:
int main(){ char tokens[100][100]; char *str = "This is my string"; tokenize(str, tokens); for(int i = 0; i < 100; i++){ printf("%s is a token\n", tokens[i]); } } void tokenize(char *str, char tokens[][]){ int i,j; //and other such declarations //do stuff with string and tokens, putting //chars into the token array like so: tokens[i][j] = <A CHAR> }
So, I understand that I cannot have char tokens[][] in my tokenize function, but if I put char **tokens in char **tokens instead, I get a compiler warning. Also, when I try to put char in my char array with tokens[i][j] = <A CHAR> , I am segfault.
Where am I mistaken? (And how ... and how can I fix it?)
Many thanks!
Isaac source share