I would like to make a string out of the data in these prints and pass it to one routine for the send. I have tried all manner of stuff and get nowhere. I would like to avoid the overhead of the string class if possible. If not I guess I can just leave the prints or pass a wack of parameter to the sendmessage routine (not elegant).
char* sendmsg; //message string to send to PC
sendmsg = ?????? //some code here to make the string up
sendmessage(sendmsg); //and use the routine instead of the prints below
Serial.print("AQ:"); //optimize this sometime by using a function
Serial.print(i); //i and v are ints
Serial.print(':');
Serial.print(v);
//one send routine for the sketch
void sendMessage(char* myString) //send a command message to the PC
{
mystring = "{" + mystring + "}" + '0'
Serial.print(myString);
}
No, it is not. It is a pointer that might someday be used to point to a block of memory where there is some character data.
sendmsg = ?????? //some code here to make the string up
Make the string from what?
mystring = "{" + mystring + "}" + '0'
You can't do that.
If you make sendmsg an array, instead of a pointer, and you use the sprintf() function to populate the array, it will already be NULL terminated. You can have the sprintf() function add the leading and trailing delimiters, or you can use three Serial.print() statements to send the {, the message, and the }.
Thanks very much. I fiddled with the code and got the sprintf to do it. I couldn't find a lot of stuff on sprintf for Arduino. Addressing modes are slowly sinking in. I'm not a C++ guy. Is there another source of knowledge for these constructs in the context of Arduino. I would at the very least like to get a handle on the sprintf formatting choices for future work. My searches were largely unprodutive.
You could have used Google or Bing or your favorite search engine to find one deliberately. A lot of usable functions are not documented on the Arduino site because thay are NOT Arduino specific.