0

How do I store the following into a char array:

AT+CIPSTART="TCP","103.6.157.239","8085"

When I do the following :

char L []="AT+CIPSTART="TCP","103.6.157.239","8085"";

I get an error :

../GPRS.c:48: error: expected ',' or ';' before 'TCP'

Jaydip Jadhav
  • 12,179
  • 6
  • 24
  • 40
Erina
  • 81
  • 1
  • 2
  • 13
  • If you're programming in C and don't know how to escape special characters in strings (line newlines or double-quotes) then I recommend you get [a good beginners book](http://stackoverflow.com/questions/562303/the-definitive-c-book-guide-and-list) or two to read. – Some programmer dude Sep 07 '17 at 05:19

2 Answers2

3

Try this

 char c[]="AT+CIPSTART=\"TCP\",\"103.6.157.239\",\"8085\"";

Micro controller escape sequences :

  • \? for ?
  • \\ for \
  • \' for '
  • \" for "
  • \b for backspace
  • \n for new line
  • \ooo for octal number
  • \t for horizontal tab
  • \v for vertical tab
  • \xxx for hexadecimal number
vikasThakur.com
  • 578
  • 4
  • 13
  • The following :AT+CIPSTART="TCP","103.6.157.239","8085" is a command to the micro controller so if I use ' \ ' will it affect my command?or during the execution will the compiler remove ' \ ' – Erina Sep 07 '17 at 05:05
  • I've edited the answer above to address your query – vikasThakur.com Sep 07 '17 at 05:33
1

In java you can escape quotes with 'backslash' \. Like for storing "TCP" in string you can use

String x= " \"TCP\" ";

Similarly you can use this concept for storing string values in array.

More on this topic, you can refer here.

Jinesh Shah
  • 922
  • 10
  • 18
  • Well, although the core answer is correct, giving Java examples and documentation to answer a C question is somewhat ... strange. – alk Sep 07 '17 at 06:28
  • Initially when the user had asked the question didn't specified the language in which the code is written nor specified the language tag. After posting the answer, the user had updated the tag as 'c'. Initially only 1 tag was there i.e. array, and at that time I presumed the language as java as it is most widely used across the world. Also at that point of time I didn't have privlage to comment in the question and ask the user about the language for the code. – Jinesh Shah Sep 07 '17 at 06:31
  • @alk. The language of the question was not made clear in the beginning – vikasThakur.com Sep 07 '17 at 09:52