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 CCS Technical Support

? operator

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







? operator
PostPosted: Sat Jan 10, 2004 4:48 pm     Reply with quote

with the fragment below I get the error

expecting :

d=d*(.25);
d==0 ? f="%05.0f" : f="%5.0f";
sprintf(s1,f,d);

I'm trying to print this value if it is zero. and with no leading zeros if d is greater than zero.

thanks
Ttelmah
Guest







Re: ? operator
PostPosted: Sun Jan 11, 2004 5:41 am     Reply with quote

piccer wrote:
with the fragment below I get the error

expecting :

d=d*(.25);
d==0 ? f="%05.0f" : f="%5.0f";
sprintf(s1,f,d);

I'm trying to print this value if it is zero. and with no leading zeros if d is greater than zero.

thanks

There are two problems here.
The first 'problem' here is a little fundamental to the CCS C. You cannot have a pointer to a constant array in ROM. The string definitions, are actually constant arrays. Hence to do this, you would need to have a storage area in RAM defined, large enough to hold the strings, with 'f' pointing to this, and then use the strcpy function to copy the constant strings into this area.
The second, is that the 'conditional expression' (?Smile syntax, is designed to 'return' the value evaluated. So, in normal C, the syntax would be:

f = (d==0 )? "%05.0f" : "%5.0f";

Unfortunately, the first problem prevents this being used.

Best Wishes
Guest








PostPosted: Sun Jan 11, 2004 7:16 am     Reply with quote

thanks. i figured it out. when all else fails read the manual.

i worked around it by using

d==0 ? sprintf(s1,"format",d):sprintf(s1,"format",d);
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