View previous topic :: View next topic |
Author |
Message |
pilar
Joined: 30 Jan 2008 Posts: 197
|
How to define a string array with multiple quotes |
Posted: Mon May 31, 2021 5:48 pm |
|
|
Hi, I am use CCS V4.074 and I need to define a string array containing quotes,
Code: | TD HD=3600,"{"d":"Demo message","t":"2021-02-26 14:51:21","seq":"00018"}" |
if I do it like this, I have a mistake
Code: | char version[] = "TD HD=3600,"{"d":"Demo message","t":"2021-02-26 14:51:21","seq":"00018"}""; |
How I can do it? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon May 31, 2021 6:23 pm |
|
|
Put a '\' symbol in front of the quotes in the middle of the text. |
|
|
pilar
Joined: 30 Jan 2008 Posts: 197
|
|
Posted: Mon May 31, 2021 6:44 pm |
|
|
Fantastic, it works! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Tue Jun 01, 2021 12:23 am |
|
|
These are known as 'escapes'. There are a number of characters that have
special significance in strings. So for example, the '\', and the '"'.
Problem is that to then have one of these inside a string, needs a way of
'escaping' this special behaviour. So in this case \" puts a " inside the
string instead of terminating the string. The full list of C escapes is:
\a Meant to be the 'alert' signal 0x7
\b Backspace 0x8
\e Escape 0x1B
\f Form feed 0xC
\n Line feed 0xA
\r Carriage return 0xD
\t Tab 0x9
\v Vertical tab 0xB
\\ Backslash 0x5C
\' Single inverted comma 0x27
\" Double inverted comma 0x22
\? Question mark (avoid trigraph)
\nnn Octal value
\xnn Hex value
Now, most of these CCS supports.
The trigraph values are special triple character sequences that make
it easier to type into strings some extra characters. The trigraphs are
defined as:
Quote: |
Trigraph: ??( ??) ??< ??> ??= ??/ ??' ??! ??-
Replacement: [ ] { } # \ ^ | ~
|
Gcc does not support these and warns you if you try to use them.
CCS does support these, so to avoid them, you have the '\?' escape.
These are potentially useless now, since most keyboards directly offer
these keys. They were useful perhaps 30 years ago, when typing C
on a terminal!...
Have fun!. |
|
|
|