Help with char operations

Hi,

I want to put a variable String to my LCD.
For example there is one Array and a constant textmessage.

If I Serial.print the content of the array everything is fine, but i need one assembled string. When i put in a + 'someString' i only get weirds.

Can somebody point me into the right direction ?
Thanks !

float currTime = millis();

char *sms[] = {"Bob","Side"};
char *disp;
int number;

void setup ()
{
Serial.begin(9600);
number = 15;
disp = sms[0] + 'car' + number;
}

void loop ()
{
number = 15;
disp = sms[0] + 'car';

//disp = sms[0] + 'car' + number;

if(millis() - currTime > 1000){
currTime = millis();
Serial.println(disp);
}
}

need one assembled string.

Method number 1:
Print them a piece at a time with Serial.print

        Serial.print(sms[0]);
        Serial.print(" car ");
        Serial.println(number);

Method number 2:
Use sprintf to assemble the pieces into an array of chars and print that with Serial.print:

        char buffer[30];// Large enough to hold longest string (+1)
        sprintf(buffer, "%s car %d", sms[0], number);
        Serial.println(buffer);

Output for either method:


Bob car 15


Regards,

Dave

Lots of things wrong here:

"millis" doesn't return a float.
"disp" is a pointer; it doesn't reserve any storage.
'car' is not a string, it is a multi-character constant.
You can't add "int"s to strings.

Suggest you look at stuff like strings, "strcat" and "itoa".

Thanks a lot for the explanation.

Silly me about the LONG millis ::slight_smile:

But, doesn´t the disp pointer point to an adress to start at and then reserve memory when defined ?

I know this is still dirty, because if anything would be after the start adress things would screw up.

greets

But, doesn´t the disp pointer point to an adress to start at and then reserve memory when defined ?

As you have declared it,char *disp;
"disp" points to the address zero.