相关疑难解决方法(0)

确定字符串文字的长度

给定一个指向字符串文字的指针数组:

char *textMessages[] = {
    "Small text message",
    "Slightly larger text message",
    "A really large text message that "
    "is spread over multiple lines"
}
Run Code Online (Sandbox Code Playgroud)

如何确定特定字符串文字的长度 - 比如第三个?我尝试使用sizeof命令如下:

int size = sizeof(textMessages[2]);
Run Code Online (Sandbox Code Playgroud)

但结果似乎是数组中指针的数量,而不是字符串文字的长度.

c arrays string literals

16
推荐指数
2
解决办法
1万
查看次数

标签 统计

arrays ×1

c ×1

literals ×1

string ×1