创建一个固定长度字符串的二维数组(字符数组)

时间:2021-04-29 21:42:09

So I've been trying to create an object in C that would essentially be two columns of empty char arrays. Its contents would resemble

所以我一直在尝试在C中创建一个基本上是两列空char数组的对象。它的内容很像

char * strings[3][2]
{
  {"thing1", "value1"}
  {"thing2", "value2"}
  {"thing3", "value3"}
}

...except the actual char *s would be empty arrays with fixed length, rather than initialized strings, i.e. each string would actually be something like "char string[6]".

...除了实际的char * s是固定长度的空数组,而不是初始化的字符串,即每个字符串实际上都是“char string [6]”。

I've been searching for some time but I'm coming up dry. Would anyone happen to know the syntax for creating such an object?

我已经找了一段时间,但我已经干了。有人会碰巧知道创建这样一个对象的语法吗?

1 个解决方案

#1


2  

Maybe like this:

也许是这样的:

typedef char sixchars[7];

sixchars strings[3][2] = { { "thing1", "value1" }
                         , { "thing2", "value2" }
                         , { "thing3", "value3" }
                         };

#1


2  

Maybe like this:

也许是这样的:

typedef char sixchars[7];

sixchars strings[3][2] = { { "thing1", "value1" }
                         , { "thing2", "value2" }
                         , { "thing3", "value3" }
                         };