Blogroll

Powered by Blogger.

Wednesday, 13 August 2014

How to put a set of " " marks inside another set of " " in Arduino program ?

by realfinetime  |  in Arduino at  00:39

         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:

IMPORTANT NOTICE

All the circuits, published in this blog is only after testing and getting proper results in my private lab. When you try these circuits, you should check the supply voltage, polarity of components, presence of childrens nearby and shorts in the circuits. This website will not be responsible for any harm happened to you or your components caused by your carelessness.

For More Electronic Tips

Blog archive

Proudly Powered by Blogger.