C 多维字符串数组
我非常简单地声明了一个字符串数组,是硬编码的,但它总是给我数组类型具有不完整的元素类型
错误。
我想这与每个数组的长度有关,但我不知道如何在不为字符串设置固定长度的情况下修复它。
char allocate[][2][] = { // Error with or without the 2
{"value1","value2"},
{"value3","value4"}
};
I'm declaring an array of strings very simply, hard-coded, but it keeps giving me the array type has incomplete element type
error.
I guess this has something to do with the length of each array but I don't know how to fix it without setting a fixed length for the strings.
char allocate[][2][] = { // Error with or without the 2
{"value1","value2"},
{"value3","value4"}
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该语法无效。如果您想要一个真正的多维数组,则必须指定除第一个维度之外的所有维度。 (编译器必须知道“内部”数组有多大,才能执行外部维度的地址计算。)
请尝试这样做:
它声明一个
const char *
的二维数组。请注意,如果您想要可以写入的字符串,那么上述方法将不起作用。
That syntax isn't valid. If you want a true multi-dimensional array, all the dimensions must be specified, except the first one. (The compiler must know how big the "inner" arrays are in order to perform address calculation for the outer dimensions.)
Try this instead:
It declares a 2D array of
const char *
.Note that if you want strings that you can write to, then the above approach will not work.