Wiring Forum
http://wiring.org.co/cgi-bin/yabb/YaBB.pl
Programming Questions & Help >> Syntax >> How to Concatenate string?
http://wiring.org.co/cgi-bin/yabb/YaBB.pl?num=1293028501

Message started by Andy on 12/22/10 at 14:35:01

Title: How to Concatenate string?
Post by Andy on 12/22/10 at 14:35:01
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

Title: Re: How to Concatenate string?
Post by barragan on 12/23/10 at 05:07:22
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;


Wiring Forum » Powered by YaBB 2.5 AE!
YaBB Forum Software © 2000-2010. All Rights Reserved.