CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

How to define a string array with multiple quotes

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
pilar



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

How to define a string array with multiple quotes
PostPosted: Mon May 31, 2021 5:48 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon May 31, 2021 6:23 pm     Reply with quote

Put a '\' symbol in front of the quotes in the middle of the text.
pilar



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

PostPosted: Mon May 31, 2021 6:44 pm     Reply with quote

Fantastic, it works!
Ttelmah



Joined: 11 Mar 2010
Posts: 19221

View user's profile Send private message

PostPosted: Tue Jun 01, 2021 12:23 am     Reply with quote

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!. Smile
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group