Getting error with multidimenstional arrays in C -


so, decided going make little ascii art game, however, when declared board, error "array type has incomplete element type." idea on how fix this?

    #include <stdio.h> #include <stdlib.h> #include <string.h>  int height = 10; int width = 12; char board[][] =            {{'-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-'},                              {'-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-'},                              {'-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-'},                              {'-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-'},                              {'-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-'},                              {'-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-'},                              {'-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-'},                              {'-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-'},                              {'-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-'},                              {'-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-'}};  void printboard(void) {     int i, j;     (i = 0; < height; i++) {         (j = 0; j < width; j++) {             printf("%c", board[i][j]);         }     } }  int main(void) {     printboard();     return 0; } 

only outer dimension can left unspecified.

change array definition to:

char board[][12] =  { ...}; 

same applies if using 3d array example:

char board3d[][12][12] =  { ...}; // ok char board3d[][][12] =  { ...}; // not ok char board3d[][][] =  { ...}; // not ok 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -