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 do I Printf a Semicolon between 2 bits of text ?

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







How do I Printf a Semicolon between 2 bits of text ?
PostPosted: Fri Jan 30, 2004 5:08 am     Reply with quote

Hi everyone,

How do I printf a Semicolon between 2 bits of text? i.e.

printf( "Here is the "problem" I have" );

I want to see :

Here is the "problem" I have

appear on my screen.

Thanks in advance, Question

Peter
P D
Guest







Sorry, Not Semicolon - I mean Inverted commas
PostPosted: Fri Jan 30, 2004 5:12 am     Reply with quote

Sorry, Not Semicolon - I mean Inverted commas

Peter
wedilo



Joined: 16 Sep 2003
Posts: 71
Location: Moers, Germany

View user's profile Send private message

PostPosted: Fri Jan 30, 2004 5:28 am     Reply with quote

Hello P D,
Normally you can use the fprintf command with %c and append the char as ascii No. 34

But I think the following way with the Backslash is also possible.

34dez = 22hex

Code:

printf( "Here is the \x22problem\x22 I have" );    ???

or...

printf( "Here is the '\x22'problem'\x22' I have" );

or...

printf( "Here is the 'problem' I have" );    :-)



I can't try it here. Please try it out and inform me...

Hope to help you
73 Sven
Ttelmah
Guest







PostPosted: Fri Jan 30, 2004 5:43 am     Reply with quote

wedilo wrote:
Hello P D,
Normally you can use the fprintf command with %c and append the char as ascii No. 34

But I think the following way with the Backslash is also possible.

34dez = 22hex

Code:

printf( "Here is the \x22problem\x22 I have" );    ???

or...

printf( "Here is the '\x22'problem'\x22' I have" );

or...

printf( "Here is the 'problem' I have" );    :-)



I can't try it here. Please try it out and inform me...

Hope to help you
73 Sven


Potentially you can put any ASCII value into a string using the \nnn format.
The allowable 'extra' string characters are:
\a 'bell' alert character
\b 'backspace'
\f 'formfeed'
\n 'newline'
\r 'carriage return'
\t 'horizontal tab'
\v 'vertical tab'
\\ the bakslash character itself.
\? the ? character
\' the single quote character
\" the double quote character
\ooo Any ASCII character. Three octal digits
\xhh Any ASCII character. Two hex digits.

I think:
Code:

printf( "Here is the \"problem\" I have" );


Is probably clearer, and easier to remember.

Best Wishes
Guest








PostPosted: Fri Jan 30, 2004 9:53 am     Reply with quote

Hi,

I finally got

printf( "Here is the %Cproblem%C I have", 0x22, 0x22 );

to work

I think I tried the

printf( "Here is the '\x22'problem'\x22' I have" );

option but as soon as it saw the " it thought that was the end of the string and carried on to make nonsense of the rest.

I can't use ' as the " is part of a fixed protocol I am working on.

I will try all the others and see what works and which is the most compact.

Thanks for the help everyone,

Peter
Al



Joined: 13 Nov 2003
Posts: 28
Location: Belfast

View user's profile Send private message

PostPosted: Fri Jan 30, 2004 10:41 am     Reply with quote

This works for me and it is simple.

printf("\r\n the \"problem\" i am having"); Smile
_________________
Alan Murray
dgoldman



Joined: 24 Aug 2010
Posts: 7

View user's profile Send private message

A broken corner case to watch for:
PostPosted: Tue Aug 24, 2010 2:52 pm     Reply with quote

Broken corner case to watch for:

#define FOO "D=1\""
printf(FOO);

doesn't work on PCWH 4.111. I think it is the double "".

To get this to work, change to
#define FOO "D=1\x22"
printf(FOO);
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Wed Aug 25, 2010 1:54 am     Reply with quote

the \ is the escape char in C, if you escape a " e.g. "\"" then the compiler should ignore this as a start/end of string qualifier and just use it as a quote char.

printf ("Here is the \"problem\" I have");

Should work, if it does not then there is an error in the compiler.

To actually display a \ you would
printf("\\");
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Wed Aug 25, 2010 7:40 am     Reply with quote

This is what I used in my code:
Code:

printf("AT+CPMS=\"ME\",\"ME\",\"ME\"");

_________________
CCS PCM 5.078 & CCS PCH 5.093
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