I think the best way to illustrate the method of putting one set of double quotation marks inside another set of double quotation marks is by an example.
Serial.write("AT+CCLK=\"99/12/12,04:06:30+08\"\r");
In this example, all the contents inside Serial.write function will be considered as a string. This string is for updating the date and time of a TTL GSM modem. As a command, new date and and time should be input through the command. Consider a case when Serial.write function is not used as given below.
AT+CCLK="99/12/12,04:06:30+08"
Date and time ( 99/12/12,04:06:30+08 ) will be a string for this command. When this command is put inside Serial.write function, whole command will be a string for the Serial.write function. That is, a string ( 99/12/12,04:06:30+08 ) inside another string ( AT+CCLK="99/12/12,04:06:30+08" ). If the command is put inside Serial.write function directly as shown below, program compiling will give an error because, first pair of double quotes will be considered as a string ( AT+CCLK= ). Second pair of double quotes will be considered as another string ( \r ). Programmer get confused about the part of string ( 99/12/12,04:06:30+08 ) in between these two pairs of double quotes.
Serial.write("AT+CCLK="99/12/12,04:06:30+08"\r");
To solve this problem a backward slash is put infront of the starting and ending of inner double quotes as shown below.
Serial.write("AT+CCLK=\"99/12/12,04:06:30+08\"\r");
Now compile the program. This will not give any errors.
0 comments: