How to find the length of an char array in c

后端 未结 6 1181
野性不改
野性不改 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:43

    You are making an array of char* and not of char. That's why strlen won't work. Use

    sizeof(s) / sizeof(char*) //should give 3
    

    If you want a single string use

    char s[] = "sab";
    

提交回复
热议问题