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

Printf - Please help

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



Joined: 12 Oct 2003
Posts: 13

View user's profile Send private message

Printf - Please help
PostPosted: Tue Mar 15, 2005 12:14 pm     Reply with quote

I have a signed long in the range of -5000 to +5000 representing a temperature between -500,0 to +500,0 degree C

When I try to convert the value to a string using the fprintf it works fine
for values between -500,0 to -1,0. But when my value is -9 (equals -0.9)
the minus sign disappears.


Anyone have the correct printf setup to solve this problem?

Thanks in advance

Poul Shocked
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 15, 2005 2:25 pm     Reply with quote

Can you post a little demo program ? Then we'll just try it.

Also post your compiler version and the PIC you're using.
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Tue Mar 15, 2005 3:39 pm     Reply with quote

Here is what I had to do recently:
Code:

           takereadings();   //reads temperature and pressure
            if (sT)     // positive temp   sT is a boolean giving the sign of temperature
               fprintf(fish,"%%temp=+");
            else        // negative temp
               fprintf(fish,"%%temp=-");

            fprintf(fish,"%02d.%01u pres=%04lu\n\r",T,(int)dT,P); // Send data to fish
                                                                  // %temp=sxx.x pres=xxxx<CRLF>

There ought to be a better way!
_________________
The search for better is endless. Instead simply find very good and get the job done.
kometen



Joined: 12 Oct 2003
Posts: 13

View user's profile Send private message

My code
PostPosted: Wed Mar 16, 2005 2:37 am     Reply with quote

Yes, there ought to be a better way.

I am using pcwh 3.216 .

My code:
int tanktoshow;
signed long temperature[20];
char string [20];

tanktoshow=1;

I am using this line to load the signed long 'temperature[tanktoshow]' to

sprintf(string,"%3.3Ld.%01Ld",temperature[tanktoshow]/10,temperature[tanktoshow]%100);


I want to have a readout with 1 decimal.
At values of 250, -250, 99,-99,9,-9 the minus sign works perfectly.


but at values -0.9, .. to -0.1 the minus sign is not added to the string.


Any nice solution is appreciated


best regards

Poul
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