Determining the Length of a String Literal

后端 未结 7 1711
栀梦
栀梦 2020-12-16 12:45

Given an array of pointers to string literals:

char *textMessages[] = {
    \"Small text message\",
    \"Slightly larger text message\",
    \"A really larg         


        
7条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-16 13:26

    You should use the strlen() library method to get the length of a string. sizeof will give you the size of textMessages[2], a pointer, which would be machine dependent (4 bytes or 8 bytes).

提交回复
热议问题