String handling help appreciated

I want to be able to send variable text strings to an LCD. I want to put the text in a variable then call the LCD handler function I am creating. I have done this thus far

char LCDMessage[200] = " "; //allocate space for 200 characters

Later in various places where I want to call the LCD handler I do the following

strcpy(LCDMessage, "some text")

then call the LCD handler which does the following (among other things)

Serial.print(LCDMessage)

All of this works fine but I would love to have the available space I have allocated to LCDMessage be variable. Perhaps I define it to be 200 characters and then inadvertently send 205 characters...oops!

Is there a way to make this more dynamic? Am I going about the string handling in the right way to begin with?

Thanks,

Jim, K6JMG

What about passing your message string to the lcdhandler as an argument.

If you want to set up the string in one place and then use it in another, why not use a pointer? For example:

char **lcd_message;

char my_message[] = "Hola, mundo";

*lcd_message = "Hello, world";
display_message();
*lcd_message = my_message;
display_message();
...
void display_message(void)
{
Serial.print(*lcd_message);
}

Why have a display_message function that relies on a global variable?

Better would be:

void display_message(char *theMessage)
{
    Serial.print(theMessage); // or LCD.print(theMessage);
}

Then call it:

char my_message[] = "Hola, mundo";
display_message(my_message);

display_message("Print this, you LCD!");