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?

piku_baba
  • 59
  • 7
  • 1
    Possible duplicate of [2D array initialisation in C](https://stackoverflow.com/questions/4409591/2d-array-initialisation-in-c) – Amir Oveisi Oct 20 '18 at 08:28
  • Do you want to be able to modify those "string"s during run-time? – alk Oct 20 '18 at 08:46

2 Answers2

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"};
arjunkhera
  • 929
  • 6
  • 23
  • 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? – piku_baba Oct 21 '18 at 13:39
  • 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](https://stackoverflow.com/questions/12813494/why-do-we-need-to-specify-the-column-size-when-passing-a-2d-array-as-a-parameter) and [this](https://stackoverflow.com/questions/19285028/why-must-n-1-dimensions-be-specified-explicitly-when-initiailizing-an-n-dimensio?noredirect=1&lq=1) for an in depth explanation. – arjunkhera Oct 21 '18 at 13:57
1

You can declare like this :

char *division[]={"Northeast Division","Northwest Division","Southeast Division","Southwest Division"};
SegFault42
  • 56
  • 3