0

I'm trying to do a 2d wchar_t array initialization using that code:

const wchar_t* e[6][]={
    { L"ç", L"$^^" },
    { L"ç"},
    { L"ç", L"$^^" },
    { L"ç", L"$^^" },
    { L"ç", L"$^^" },
    { L"ç", L"$^^" }
};

but I get an error when compiling:

array type has incomplete element type

so what's wrong and what to do to solve that problem?

1
  • What you are trying to declare isn't a 2D-array to wchar_t, but to pointers to wchar_t. Commented May 13, 2014 at 13:10

2 Answers 2

3

The only optional length when declaring an array is the first one, so in your case you need to specify the second one:

const wchar_t *e[][2] ;

Moreover be carefull that the array in second position is filled with NULL value at the end:

{L"ç"} 
// is in fact
{L"ç", NULL}
Sign up to request clarification or add additional context in comments.

9 Comments

this array should have different sized lines: so the 2nd line can have a different size.
@user3457200 It is not possible to create static array with different length for each line in C.
I tested this array as it was with doing 'const wchar_t *e[][2]' on a test program, and it worked fine for me.
@user3457200 It's because your array is automtically filled with NULL value at the end, but its size is still 2.
@Holt you can omit initializers, it would initialize missing items with a null pointer.
|
1

The way you are declaring the array is wrong... You should be doing...

const wchar_t* e[][6] instead of const wchar_t* e[6][]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.