Declaring an array of character pointers (arg passing)

Posted by Isaac Copper on Stack Overflow See other posts from Stack Overflow or by Isaac Copper
Published on 2010-05-04T22:18:04Z Indexed on 2010/05/04 22:28 UTC
Read the original article Hit count: 176

Filed under:

This is something that should be easy to answer, but is more difficult for me to find a particular right answer on Google or in K&R. I could totally be overlooking this, too, and if so please set me straight!

The pertinent code is 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", token[i]);
    }
}
void tokenize(char *str, char tokens[][]){
    //do stuff with string and tokens, putting
    //chars into the token array like so:
    tokens[i][j] = <A CHAR>
}

So I realize that I can't have char tokens[][] in my tokenize function, but if I put in char **tokens instead, I get a compiler warning. Also, when I try to put a char into my char array with tokens[i][j] = <A CHAR>, I segfault.

Where am I going wrong? (And in how many ways... and how can I fix it?)

Thanks so much!

© Stack Overflow or respective owner

Related posts about c