How to find the length of an char array in c

后端 未结 6 1362
野性不改
野性不改 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条回答
  •  太阳男子
    2021-02-06 12:44

    There is no direct way to determine the length of an array in C. Arrays in C are represented by a continuous block in a memory.

    You must keep the length of the array as a separate value.

提交回复
热议问题