How to find the length of an char array in c

后端 未结 6 1171
野性不改
野性不改 2021-02-06 12:06

I want to find the length of this :

char *s[]={\"s\",\"a\",\"b\"};

it should count 4 with the /0 but the strlen or sizeof(s)/sizeof(char) gives

6条回答
  •  梦毁少年i
    2021-02-06 12:26

    What you have defined is not a string hence there is no NULL terminating character. Here you have declared pointers to 3 separate strings. BTW, you should declare your array as const char*.

提交回复
热议问题