Convert int to char and append to buffer

I have a char array that is partially filled with text and I want to convert an int to char and append to end of current text in the buffer. Is there a simple command to do this instead of converting int into another buffer and using strcat?

char buffer[100] = {"Something already there ="};

int number = 16;

//buffer=buffer+str(number)

// results in buffer containing "Something already there =16"

1 Like
itoa(number, buffer+strlen(buffer));

Thanks michael_x,
I had almost got there with itoa(x,chrBuffer[strlen(chrBuffer)],10); and wondering how to convert char to char* (I really don't get C programming with pointers).
Next question is how to append a space character?

    x=strlen(chrBuffer);
    chrBuffer[x] = " \0";

does not work.

    x=strlen(chrBuffer);
    chrBuffer[x] = ' ';
    chrBuffer[x+1] = '\0';
strcpy(buffer+strlen(buffer), " ");

Edit: fixed param order

I really don't get C programming with pointers.

I really think you should take the time and learn to understand the pointers. They are absolutely crucial in the C/C++ programming. And it's not that hard to learn really.

... the difference between char and char* is related to the difference between
'a' and "a" .
It's worth trying to understand that, too.

And it's not that hard to learn really.

Yes :slight_smile:

... the difference between char and char* is related to the difference between
'a' and "a" .

I understand the principal of pointers but it's the syntax that gets me.
I changed my code to use ' instead of " and it works but what is the special meaning of ' compared to " in C++
Also the arduino reference does not seem to mention little nuggets like itoa() and dtostrf(). Omissions like that steepens the learning curve.

' denotes a character. " denotes a pointer to an array of characters.

' is equivalent to a char, " is equivalent to a char* or a char[].