|
|
View previous topic :: View next topic |
Author |
Message |
piccer Guest
|
? operator |
Posted: Sat Jan 10, 2004 4:48 pm |
|
|
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 |
Posted: Sun Jan 11, 2004 5:41 am |
|
|
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' (? 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
|
|
Posted: Sun Jan 11, 2004 7:16 am |
|
|
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); |
|
|
|
|
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
|