1

I am trying to declare this array of strings(or a 2d character array,i reckon) in c language but the compiler ide is giving me error: "[Error] array type has incomplete element type"

char division[][]={"Northeast Division","Northwest Division","Southeast Division","Southwest Division"};

what am I doing wrong?

asked Oct 20, 2018 at 8:27
2
  • 1
    Possible duplicate of 2D array initialisation in C Commented Oct 20, 2018 at 8:28
  • Do you want to be able to modify those "string"s during run-time? Commented Oct 20, 2018 at 8:46

2 Answers 2

1

You have to specify the maximum length of a string. This should solve your problem

char division[][25]={"Northeast Division","Northwest Division","Southeast Division","Southwest Division"};
answered Oct 20, 2018 at 8:46
Sign up to request clarification or add additional context in comments.

2 Comments

in 1d array you dont need to do that if you given whats in the array...so why do you need to do that in 2d?
because if we do not specify the row length, then the compiler will have no way of knowing how to deference other row elements. Check this and this for an in depth explanation.
1

You can declare like this :

char *division[]={"Northeast Division","Northwest Division","Southeast Division","Southwest Division"};
answered Oct 20, 2018 at 9:47

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.