Clearing a char array..

char msgPart1[11];
char msgPart2[11];
char msgPart3[11];
char msgPart4[11];

char tempLCD[21];

...
...
..

setup()
{

// Lcd init code goes here 


  lcd.clear();
  strcat( tempLCD, msgPart1);
  strcat( tempLCD, msgPart2);
  lcd.print( tempLCD);              // First Line of LCD prints fine...

  lcd.setCursor(0, 1);
  
  tempLCD[] = {""};                // Tried to clear the tempLCD but have not been able to ...

  strcat( tempLCD, msgPart3); 
  strcat( tempLCD, msgPart4);
  lcd.print( tempLCD);              // If not cleared the first line content remains !!

As can be seen i am using the tempLCD[21] to print the concatenated char to each line and require to clear it before printing to the next line. ( I am using a 4 line x 20 Char LCD)

How to do this ??

You could use

  strcpy( tempLCD, msgPart3);
  strcat( tempLCD, msgPart4);

When you print a char array, characters will be displayed one after another untill the null terminating character.
So, this should be sufficient:

tempLCD[0] = 0; // or '0'

Goet:
When you print a char array, characters will be displayed one after another untill the null terminating character.
So, this should be sufficient:

tempLCD[0] = 0; // or '0'

Ohh, so close. you mean '\0', '0' is decimal 48.

yup, forgot the slash : p

I still think replacing the first strcat by strcpy is the better solution, it's smaller and faster.
Concatenating to a known empty string seems not very sensible to me.
And you can not forget any backslashes... :wink:

Whandall:
I still think replacing the first strcat by strcpy is the better solution, it's smaller and faster.

Agree, I was a little superficial in my reply : )

There is no need to clear a string buffer in string composition,
many string functions just ignore the previous content and set a valid delimiter.

Wow ... that was super simple. Both methods suggested by Goet and Whandall work. Thanks folks. That was good learning.

Ok so now that the issue is cleared i am am working on a logic to exactly fit in the tempLCD to occupy 20 char width so that the display looks neatly filled.

Like for instance its not always that msgPart1 and msgPart2 are exactly 10 char width. They will be anything from 1 to 10. So the msgpart2 will need to start at the 11th position on the LCD ... i guess i just have to pad up the unused char positions in msgPart1 with required number of spaces.

Will do and revert if i get stuck !!

Ok here we go… this one does exactly what I wanted. Though it looks too much of a circus to do !!

/*
  04 Aug 2017

  Code to demonstrate the method to build a char array and send to LCD

  LCD : 20 Character x 4 Line interfaced using I/O expander I2C interface

*/
//=================== INCLUDE ====================

// Include Libraries :
//#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>


// Define the LCD pins to use and Initialize an instance
LiquidCrystal_I2C  lcd(0x27, 2, 1, 0, 4, 5, 6, 7);        

byte led13 = 13;

char msgPart1[11]  = "   LCD";
char msgPart2[11]  = "CheckOut !";
char msgPart3[11]  = "  Trial";
char msgPart4[11]  = "Version1.0";
char msgToPrint[21]; 

//================= SETUP =========================
void setup()
{
  // START SERIAL FOR DEBUGGING
  Serial.begin(9600);
  // Usage : Serial.println(variable);

  // START THE I2C INTERFACE
  Wire.begin();

  // START THE LCD INTERFACE

  lcd.begin(20, 4);
  lcd.setBacklightPin(3, POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.clear();

  padLcdMsg(msgPart1);                   // Start printing the message..first two lines.
  strcat(msgToPrint, msgPart1);
  strcat(msgToPrint, msgPart2); 
  lcd.print(msgToPrint); 
  lcd.setCursor(0,1);
  padLcdMsg(msgPart3); 
  strcpy(msgToPrint, msgPart3);
  strcat(msgToPrint, msgPart4); 
  lcd.print(msgToPrint); 
  
  pinMode(led13, OUTPUT);
  digitalWrite( led13, HIGH);

}

//================ SCAN LOOP ======================
void loop()
{
  
}
//================ SCAN LOOP END =================

// Function to pad spaces to unused part of a message and null terminate it.
void padLcdMsg ( char * partMsg)
{
  byte part1Len = strlen(partMsg); 
  for ( byte count = part1Len; count <10; count++)
  {
    partMsg[count] = ' ';
  }
  partMsg[10] = '\0';
}

Ardubit:
Ok here we go... this one does exactly what I wanted. Though it looks too much of a circus to do !!

if you are going through all of this, why not just add the spaces to the end of your partial messages and not go through all the padding machinations?

It's not like you are conserving SRAM using these arrays (using 11 bytes each even though a couple are smaller):

char msgPart1[11]  = "   LCD";
char msgPart2[11]  = "CheckOut !";
char msgPart3[11]  = "  Trial";
char msgPart4[11]  = "Version1.0";