Putting declared const into a print statement
-
So, I have this snippet of code that formats an html table data cell:
if(aSensor\[i\].sensorSwitchState == lowState) { client->print(""); } else { client->print(""); // }
I have each background-color: hardcoded and the subsequent printing output is as I was expecting. However, I would like to replace the entry - lawngreen and/or red - with a const (or #define) so that the entry is replaced with the color name. I've tried #define GREEN lawngreen ...
client->print("")
and that doesn't work. I've tried const char acolor[]="lawngreen";
client->print("")
and that doesn't work. I know there has to be a way to do this, but I can't seem to figure it out. Any ideas how I go about making a declaration that will let me insert the in the appropriate place would be greatly appreciated. TNX
-
So, I have this snippet of code that formats an html table data cell:
if(aSensor\[i\].sensorSwitchState == lowState) { client->print(""); } else { client->print(""); // }
I have each background-color: hardcoded and the subsequent printing output is as I was expecting. However, I would like to replace the entry - lawngreen and/or red - with a const (or #define) so that the entry is replaced with the color name. I've tried #define GREEN lawngreen ...
client->print("")
and that doesn't work. I've tried const char acolor[]="lawngreen";
client->print("")
and that doesn't work. I know there has to be a way to do this, but I can't seem to figure it out. Any ideas how I go about making a declaration that will let me insert the in the appropriate place would be greatly appreciated. TNX
-
So, I have this snippet of code that formats an html table data cell:
if(aSensor\[i\].sensorSwitchState == lowState) { client->print(""); } else { client->print(""); // }
I have each background-color: hardcoded and the subsequent printing output is as I was expecting. However, I would like to replace the entry - lawngreen and/or red - with a const (or #define) so that the entry is replaced with the color name. I've tried #define GREEN lawngreen ...
client->print("")
and that doesn't work. I've tried const char acolor[]="lawngreen";
client->print("")
and that doesn't work. I know there has to be a way to do this, but I can't seem to figure it out. Any ideas how I go about making a declaration that will let me insert the in the appropriate place would be greatly appreciated. TNX
-
This
#define GREEN "lawngreen"
client->print("")should work. There might be more elegant ways, depending on
print
function definition.To both K5054 and Cpallini: Thanks, that gets the job done!! It turns out I had tried #define GREEN "lawngreen" but then wrote the code escaping the quotes:
client->print("");
I had also tried
client->print("");
but that didn't work. Its the space after the leading quote that does the trick.
client->print("");
The trailing quote doesnt need a space before it. Gotta think on that one a bit (why the quotes and their spacing is important but escaping the quotes is not) :)
-
To both K5054 and Cpallini: Thanks, that gets the job done!! It turns out I had tried #define GREEN "lawngreen" but then wrote the code escaping the quotes:
client->print("");
I had also tried
client->print("");
but that didn't work. Its the space after the leading quote that does the trick.
client->print("");
The trailing quote doesnt need a space before it. Gotta think on that one a bit (why the quotes and their spacing is important but escaping the quotes is not) :)
In C/C++ consecutive string literals are catenated together
cout << "hello " "world" << endl;
cout << "hello world" << endl;both produce the same thing. I don't know why the C++11 standard requires a space between a literal and a string macro, but it probably has something to do with ambiguous parsing when no space is present. As for the escaped quotes, if you mean
client->print("");
recall that
\"
embeds a double quote in a string, much like\n
or\t
embeds a new-line or a tab. If that's not what you were referring to, then maybe you could explain it better? -
In C/C++ consecutive string literals are catenated together
cout << "hello " "world" << endl;
cout << "hello world" << endl;both produce the same thing. I don't know why the C++11 standard requires a space between a literal and a string macro, but it probably has something to do with ambiguous parsing when no space is present. As for the escaped quotes, if you mean
client->print("");
recall that
\"
embeds a double quote in a string, much like\n
or\t
embeds a new-line or a tab. If that's not what you were referring to, then maybe you could explain it better?Frankly, I had forgotten the concatenation example you show. As for your escaped quotes, yes, I was referring to the use of the \ to allow the explicit use of the the following ". I thought that since the contents of the print statement were already delineated by leading and trailing quotes, that I had to use the \ to permit the use of additional quotes between those two "bookend" quotes. Thanks for setting me straight. Its been a good day - I learned something. Thank you!!