Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think the question here is whether you can statically declare a multi-dimensional array of C style strings where there are a different number of strings on each row. So, something like this:</p> <pre><code>const char * arr[][3] = { {"bla", "bla", "bla"}, {"bla", "bla" } }; </code></pre> <p>In some languages this is referred to as a "jagged array." In C and C++ you can do this, though the compiler will want to allocate space to store all the rows as though they're the same length, so you'll end up not initializing the 3rd item of the second array. When I tested this out on gcc the third item in that array was set to NULL, but I don't know if you can count on that.</p> <p>I don't think you'll be able to get the compiler to accept arrays declared like {1,2,3} as C style strings. Even if it did, and you treated these as strings, you'd have a problem since they're not null terminated.</p> <p>I'd agree with the other posters, a better approach is probably to store this data in XML, yaml, or possibly in the database you're taking them from, and access them there. If you do need to create these statically in a source file you'll probably be better off declaring a structure that makes sense for your data and initializing an array of those. Something like:</p> <pre><code>typedef struct { const char * somestring; const char * someotherstring; const unsigned int triple[3]; } Abbreviation; const Abbreviation abb[] = { {"First Thing", "Second String", {1,2,3} }, {"Other Thing", "Some String", {4,5,6} } }; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload