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

Declaring (initializing) array without size

Hi!

I'm having some problems declearing an array. I am trying to make an array that contains messages that I will later display on an LCD display. I am using a 2D char array, but I don't want to specify a fixed size to the second dimension. At the moment i am doing this:

const char message[][20] = {
	"RS232 Monitor",
	"By: Oyvind Tjervaag",
	"V1.0",
};

The problem with this is that a lot of space is wasted scince there is only one string that fills up the 20 chars. Here the "V1.0" string will be the 4 chars I want to use followed by 16 0x00...

The annoying thing about this is that I have have done it before.. But I can't find the code where I did it...

I thought I could do it like this:

const char message[][] = {...}
But that is just giving me the error, "Too many initializers" , which of course means that I am trying to add more variables than what can fit into the array.

Could someone give me any hints about this?

Thanks
Øyvind

Parents
  • Hi,

    Nice idea. I'm ew in embedded C and working on a nice project with a LCD. Therefore I'm writing a Hitachi 44780 module. It is workig perfect ut what I like to know is how to put a string to a LCD. The following a tried:

    /*
    //  Write a string to the LCD *** Doesn't work at the moment *** Help needed!!!
    */
    void LCD_String (char ROW, char COL, char *string)
    {
    	GoToXY (ROW, COL);
    	while (*string)
    		LCDdata (*string++);
    }
    

    char lcdstr = "LCD Ready";
    LCD_String(1,1,*lcdstr);
    

    If I try this, nothing apears on the LCD.

    "GoToXY" and "LCDdata" are working perfectly because I tried it seperatly.

    If I introduce the "LCD_String", No string on the LCD.

    Do I need to include some libraries?
    Or what else do I wrong?

Reply
  • Hi,

    Nice idea. I'm ew in embedded C and working on a nice project with a LCD. Therefore I'm writing a Hitachi 44780 module. It is workig perfect ut what I like to know is how to put a string to a LCD. The following a tried:

    /*
    //  Write a string to the LCD *** Doesn't work at the moment *** Help needed!!!
    */
    void LCD_String (char ROW, char COL, char *string)
    {
    	GoToXY (ROW, COL);
    	while (*string)
    		LCDdata (*string++);
    }
    

    char lcdstr = "LCD Ready";
    LCD_String(1,1,*lcdstr);
    

    If I try this, nothing apears on the LCD.

    "GoToXY" and "LCDdata" are working perfectly because I tried it seperatly.

    If I introduce the "LCD_String", No string on the LCD.

    Do I need to include some libraries?
    Or what else do I wrong?

Children