0

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?

1 Answer 1

2

Maybe like this:

typedef char sixchars[7];

sixchars strings[3][2] = { { "thing1", "value1" }
                         , { "thing2", "value2" }
                         , { "thing3", "value3" }
                         };
Sign up to request clarification or add additional context in comments.

3 Comments

@RobertHarvey: There are six lights.
This also appears to be working: For a two-dimensional array of character arrays of length 20, with 3 rows and 2 columns: char (myarray[3][2])[20].
@EricFields: Sure, you don't need the typedef. I just put it in there for readability.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.