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", };
const char message[][] = {...}
You are creating a 2-dimensional array. What you probably want is an array of pointers (to strings). For example:
char *array [] = { "This", "is", "an", "array", "of", "pointers", "to", "strings.", };
Ahh... Yes, just tried it and that seems to be exactly what I need.. Thanks Jon, Øyvind
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);
You have defined lcdstr to be a single char, whereas you need a string: Try either
char * lcdstr = "LCD Ready";
char lcdstr [] = "LCD Ready";
Thanks for the fast reply. But.... neither functions seems to work. The first one come through the compiler but no string on the LCD. Infact, same result as I allready had. The other seems to bother the compiler. I get an error message error: need array size So.... I got dont know what to do....
Is this what you ended up with? (This works fine for me.)
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);