Concatination of string


Here i want to add two string( concatenate, append).
one string from serial monitor(User input) and the other is from existing string in the code.
For example if user pressed avinash. and the code has global string with value hello. then output should be as hello avinash. but we should not use Serial.print and serial.printl to paste them side by side in serial monitor. I want to concatenate them. But I'm unable to do this. There are errors saying that i cant concatenate two char with +operator. I tried strcpy, c_str(). nothing workd. there is also a error saying that i cnat convert string to char.
Please help to solve this...........

You need to post your code.

When is our assignment due?

Read the forum guidelines. Post your code in code tags. Use the IDE autoformat tool (ctrl-t or Tools, Auto Format) to indent the code for readability before posting code.

Please do not post pictures of code, Serial output and error messages

You can right click on code in the IDE and select "Copy for forum" and paste the code here. Code tags will be added by the IDE

You can also copy error messages using the "Copy error message" button and paste that here and select Serial output and copy it to the clipboard using Ctrl+C. When pasting error messages and Serial output please add code tags yourself. See How to get the best out of this forum

Your Serial Monitor line ending is set to "Both NL & CR". Both of those get sent with your data and end up in your string. When you type "hello" your sketch sends back "hello\n\rGURU". Set your line ending to "No line ending" and it will send back "helloGURU". If you want to get back "hello GURU" (with a space) you need to either type "hello " (with a space) or change "GURU" to " GURU" (with a space).

1 Like

add
str.trim(); // gets rid of the \r or \r\n
before
Serial.println(str+str2);

If you are using Strings check out my Taming Arduino Strings tutorial.

Thank you for sharing your knowledge

In C, strings have 0x0 in the end, but chars don't. I made that mistake a few days ago. You can't concat strings and chars.
But something like this works.
char testing[2];
char notastr;
.......
.....
testing[1]=0x0;
testing[0]=notastr;
//now concat works