LCD printing vars??

Hi all, im newish to arduino and for the life of me cannot get this to work.

Ive worked quite a bit on my project now and all im trying to do is print a number + string to the LCD screen.

The number is an int and upto now all ive done is lcd.print(numberVar+" string")

But instead now i want the string to be a variable, but i cannot get it to compile.

Ive tring char,char* & string to declare the string. but all i get is:

invalid operands of types 'const char*' and 'char [4]' to binary 'operator+'

the above error is with the string declared as:

char currentUnit[] = "C";

and the lcd print as:

lcd.print(currentVal+" "+currentUnit);

if i change the lcd print to: lcd.print(currentVal+" C"); it works fine?

what am i doing wrong?

thanks Andy

 lcd.print(currentVal+" "+currentUnit);

How would you like the Arduino to ADD these values? That's what the + operator does.

lcd.print(currentVal);
lcd.print(" ");
lcd.print(currentUnit);

ok, i see that but i thought the + operator “concentates” strings?

If obviously it does, how do you concentate string variables?

Andy

Each constant or variable needs its own print statement. PaulS showed you the correct code.

Edit: typo...

but i thought the + operator "concentates" strings?

If obviously it does, how do you concentate string variables?

It is an operator in the String class, too. A String is not the same as a string. A string is a NULL terminated array of chars. There is no operator to concatenate strings. There is a function, strcat(), that can.

Ok thanks, ive implimeted it as in your code and that works great.

Thanks Andy