How do I put quotes in a string? I want to put this as a string:
The quotes are not optional. This is an AT command that requires them.
//this works because the command doesn't require internal quotes:
char smsMode = "AT+CMGF=1";
//this does not
char memSim = "AT+CPMS="SM"";
I get this error:
error: expected ',' or ';' before 'SM'
Nevermind. I answered my own question. Double quotes will make it happen:
char memSim = "AT+CPMS=""SM""";
Really? Normally doubled quotes would do something a bit different, and you'd use backslash:
char memSim = "AT+CPMS=\"SM";
Your way worked! Thanks! Just because my previous code would compile, it didn't mean it would work (it didn't).
#define PHONE_MEM_TO_PHONE "AT+CPMS=\"ME\""
made the desired:
char memSim = "AT+CPMS=""SM""";doubled quotes would do something a bit different
For the curious, what happens when you use doubled quotes with gcc is that the compiler sees two strings, and automatically concatenates them into a single string in the binary. This is particularly useful when you're trying to construct very long strings:
char *poem = "I think that I shall never see\n"
" A matrix lovely as a tree\n"
"Trees are fifty times as fun\n
" As structures ala PL/1";
Since the compiler mostly ignores whitespace/newlines, and the final string gets only the material from between the quotes, you can format your source code to look like the string should look when its finally printed. (Of course, you can also mislead yourself and have them NOT match. Leaving out the "\n"s is common...)
Hey joy*C*e_kilmer, you missed a quote on line three of your poem. :)
I heard that the original reason for gluing C string literals was to support concatenation with the preprocessor. For example,
#define MODEL [glow]"Frappinator"[/glow]
#define VERSION [glow]"2.43"[/glow]
const char* message = [glow]"Revoco "[/glow] MODEL [glow]", version "[/glow] VERSION [glow]"\n"[/glow]
[glow]"All Rights Reserved."[/glow];
Thanks! using the \" worked!, not if I could only get the arduino to send data, read the reply, and print it back out.