Eric Fields
Eric Fields

Reputation: 125

Creating a two-dimensional array of fixed-length strings (character arrays)

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

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]".

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?

Upvotes: 0

Views: 607

Answers (1)

Kerrek SB
Kerrek SB

Reputation: 476950

Maybe like this:

typedef char sixchars[7];

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

Upvotes: 2

Related Questions