Home \ Help \ Search \ Login RSS

Welcome, Guest. Please Login

This forum is now READ-ONLY! Please visit http://forum.wiring.co/ for the new forum.

Wiring ForumProgramming Questions & HelpSyntax › How to Concatenate string?

Page Index Toggle Pages: 1
How to Concatenate string? (Read 3481 times)
12/22/10 at 14:35:01

Andy   Offline
YaBB Newbies
Terre Haute, Indiana

Posts: 45
*
 
Can't for the life of me figure out how to concatenate a string!  Any help with the following?

Code:
String ConvertBooleanToString();
char statusword[99];
boolean DistanceOnOff = false;

//the above just to show how things are defined

void MakeStatusWord(){
  strcpy(statusword, ConvertBooleanToString(DistanceOnOff));
  strcat(statusword, someotherstring);
}

String ConvertBooleanToString(boolean str){
  if (str == true) {
    return "Y";}
  else{
    return "N";}
}
 



I receive this error:

/tmp/build8642427688097957793.tmp/george_12_21_10.cpp:255: error: cannot convert 'String' to 'const char*' for argument '2' to 'char* strcpy(char*, const char*)'
error: cannot convert 'String' to 'const char*' for argument '2' to 'char* strcpy(char*, const char*)'

Any ideas or better method?

Many thanks
 
IP Logged
 
Reply #1 - 12/23/10 at 05:07:22

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
It should be something like this:

String statusword = "";

String & ConvertBooleanToString(boolean str){
  if (str == true) {
    return "Y";}
  else{
    return "N";}
}




statusword = ConvertBooleanToString(DistanceOnOff);
statusword += someotherstring;

 
IP Logged
 
Page Index Toggle Pages: 1