How do I create an array of strings in C?

前端 未结 14 2673
野的像风
野的像风 2020-11-22 14:43

I am trying to create an array of strings in C. If I use this code:

char (*a[2])[14];
a[0]=\"blah\";
a[1]=\"hmm\";

gcc gives me \"warning:

14条回答
  •  旧时难觅i
    2020-11-22 15:23

    The string literals are const char *s.

    And your use of parenthesis is odd. You probably mean

    const char *a[2] = {"blah", "hmm"};
    

    which declares an array of two pointers to constant characters, and initializes them to point at two hardcoded string constants.

提交回复
热议问题