2D character array initialization in C

前端 未结 4 1583
臣服心动
臣服心动 2021-02-03 10:23

I am trying to build a list of strings that I need to pass to a function expecting char **

How do I build this array? I want to pass in two options, each wi

4条回答
  •  半阙折子戏
    2021-02-03 10:51

    C strings are enclosed in double quotes:

    const char *options[2][100];
    
    options[0][0] = "test1";
    options[1][0] = "test2";
    

    Re-reading your question and comments though I'm guessing that what you really want to do is this:

    const char *options[2] = { "test1", "test2" };
    

提交回复
热议问题