This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

two dimentional array(char) problem

hi !

I want a table from which i can take char data. so i have used char 2-dim array.my initialization is ok. but complier gives following error :

MAIN.C(24): error C242: 'array[]': too many initializers

unsigned char  guj_powerfail[8][5]= {{0x1b,0x0b,0x0b,0x0b,0x0f,0x03,0x03,0x00},
                                                                                  {0x19,0x11,0x11,0x11,0x13,0x1d,0x01,0x00},
                                                                                  {0x1c,0x04,0x04,0x1c,0x08,0x08,0x0c,0x00},
                                                                                  {0x00,0x00,0x1d,0x05,0x05,0x05,0x1d,0x00},
                                                                                  {0x0f,0x00,0x1b,0x0b,0x1b,0x13,0x1f,0x00}};

Please help.

  • So have you considered which of [5] and [8] that represents which dimension of your array?


  • my initialization is ok. but complier gives following error

    If the initialization would be ok, the compiler wouldn't give you an error... doesn't it?

  • The diagnostics given by a "small" compiler like C51 can often be quite limited - so it can be informative to also pass the code through another compiler.

    eg, GCC gives the following set of warnings for that code:

     warning: excess elements in array initializer
     warning: (near initialization for 'guj_powerfail[0]')
     warning: excess elements in array initializer
     warning: (near initialization for 'guj_powerfail[0]')
     warning: excess elements in array initializer
     warning: (near initialization for 'guj_powerfail[0]')
    
     warning: excess elements in array initializer
     warning: (near initialization for 'guj_powerfail[1]')
     warning: excess elements in array initializer
     warning: (near initialization for 'guj_powerfail[1]')
     warning: excess elements in array initializer
     warning: (near initialization for 'guj_powerfail[1]')
    
     warning: excess elements in array initializer
     warning: (near initialization for 'guj_powerfail[2]')
     warning: excess elements in array initializer
     warning: (near initialization for 'guj_powerfail[2]')
     warning: excess elements in array initializer
     warning: (near initialization for 'guj_powerfail[2]')
    
     warning: excess elements in array initializer
     warning: (near initialization for 'guj_powerfail[3]')
     warning: excess elements in array initializer
     warning: (near initialization for 'guj_powerfail[3]')
     warning: excess elements in array initializer
     warning: (near initialization for 'guj_powerfail[3]')
    
     warning: excess elements in array initializer
     warning: (near initialization for 'guj_powerfail[4]')
     warning: excess elements in array initializer
     warning: (near initialization for 'guj_powerfail[4]')
     warning: excess elements in array initializer
     warning: (near initialization for 'guj_powerfail[4]')
    

    which gives you more of a clue as to what is wrong with your code.

    "my initialization is ok"

    As already noted, if it was OK, you would not get the error - would you?!

  • whatever happens it is ALWAYS the fault of the tools.

    I wonder if the OP has disappeared having found the GLARING error by him/herself

    Erik