Concatenate to a char array / converting integers?


recently started playing with an ST7565 LCD screen using Adafruit's library - which still uses char arrays for strings. My plan for this screen is to use it to output debug info, but my problem is trying to build one long string out of all the variables i have strewn about.

I've always been kind of bad at concat'ing strings together, but char arrays are a whole other beast of frustration for me. Here's what i'm trying to do:

I have 3 variables - Var1, Var2, Var3

What i want to send to the display is "Variable 1: (var1) Variable 2: (var2) Variable 3: (var3)" as a char array.

Any tips?

I have 3 variables - Var1, Var2, Var3

And the types of the variables are..?

for ease, lets just say All integers.

It depends on what type of variable you want to concatinate. If it's an integer, it shouldn't be too difficult. Integers are stored in memory as 2 bytes. Each character is stored as 1 byte.

However, the value stored in each byte contains more than 1 digit worth of information. This is where the complexity comes in. Rather than extracting each byte with HighByte() and LowByte() functions, you'll need to write some code that extracts each digit (0-9 for decimal values) individually.

Once you have a digit individually, it can be saved in a char or a byte variable. The main difference between byte and char variables is that bytes are just hexidecimal numbers. Chars are also a single-byte hexidecimal number, but chars have the understanding that the data contained in them conforms to ASCII values and represent a language character and not a number specifically. Hence the name "char". You'll need to make sure the digit value is saved as the ASCII representation. A quick and dirty method is to add 48 to the decimal value of the integer, and that will give you the ASCII value for 0-9.

check out the sprintf() command :

for ease, lets just say All integers.

"byte"s are integers, "int"s are integers and so are "long"s.

Thanks for the input guys, i'll try what BKnight760 said and just pick through each byte