Adding to a variable

OK, I can figure out how to do most things, but this has me beat :cry:

so, starting with a char, string, int etc. containing for example "abc" or "123" and i want to add "d" or "4" leaving the variable with "abcd" or "1234" respectively

How is this done? or am I heading in the wrong direction? :wink:

If more explanation is needed i'll try an tell you what I have loosely planned, but at this stage is so loose i'm not entirely sure myself...

This is exactly what I'm trying to figure out (so I can build a GET URL to be sent to a server using the WIZnet ethernet module).

What is the append / concat operator for the Arduino language?

// This doesn't work
Serial.println("abc" . "d");

// Neither does this
Serial.println("abc" + "d");

Thanks!

You can't concatenate strings that way.

There are functions called strcpy() and strcat() which can help with these tasks, but you have to be very careful of how much memory you declare as a buffer, or you can accidentally concatenate more string than you can fit in the buffer. This will end up causing all sorts of hard-to-diagnose problems.

The "Arduino language" is C++, so any good book on C or C++ will be useful if you want to learn more.

#define mydomain "halley.cc"
#define myname "ed"

char buffer[100];  // don't build more than 99 chars to this!
strcpy(buffer, "http://");
strcat(buffer, mydomain);
strcat(buffer, "/foo/bar/baz?name=");
strcat(buffer, myname);
Serial.println(buffer);

Awesome, I've got several C++ and related books around, I'll have a look through and see what I can find.

Thanks for the little example too, perfect. I only need space for about 16 chars.

Holy crap, who comes up with this stuff?

I guess I'm just spoiled by the ease PHP and other scripting languages (I know, not true programming languages, yadda yadda).

Thanks for the example.

Of course, if you know exactly the position you need to change, you can just do that directly, for example:

myOutBuffer[4] = 'd';

=)

!c