How do I create an array of strings in C?

前端 未结 14 2535
野的像风
野的像风 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条回答
  •  遇见更好的自我
    2020-11-22 15:18

    If you don't want to keep track of number of strings in array and want to iterate over them, just add NULL string in the end:

    char *strings[]={ "one", "two", "three", NULL };
    
    int i=0;
    while(strings[i]) {
      printf("%s\n", strings[i]);
      //do something
      i++;
    };
    

提交回复
热议问题