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

Problem printing leading zeros using %w

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



Joined: 15 Jul 2005
Posts: 89
Location: UK

View user's profile Send private message

Problem printing leading zeros using %w
PostPosted: Wed Jun 27, 2007 3:36 am     Reply with quote

Hi,

I've got several signed int16s that I'm sending over a com port using the fprinf statement. In order to do this I'm use the following line:

Code:


fprintf(PORT2, "%3.1w %3.1w %3.1w \r", heading, pitch, roll);



However, the heading value can obviously be anything beween 0.0 and 359.9 and the pitch and roll values can be between -88.9 and 88.9. The problem is that they vary in length.

I'd like to fix the length of the values e.g 029.6 or 356.2 for the heading, and -19.5 or +09.5 for both the pitch and roll. Any idea how I might go about doing this using the %w print format?

Perhaps I need to just fix the length and print leading zeros for the heading e.g 029.5, and do a test for +/- and print those characters separately to the numerical value for the pitch and roll e.g. +01.4? Is there and easier way to do this rather than doing a test??

Many thanks,
Ed

PS: Using compiler version 3.235 and an 18F6722
edhaslam



Joined: 15 Jul 2005
Posts: 89
Location: UK

View user's profile Send private message

PostPosted: Wed Jun 27, 2007 7:18 am     Reply with quote

Managed to fix it by getting the field length right and by using %lw Embarassed

It's nice when you work it out by yourself Idea Smile

(with a little help from this thread: http://www.ccsinfo.com/forum/viewtopic.php?t=30640&highlight=leading+zeros Twisted Evil Many thanks Ttelmah Smile 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