edhaslam
Joined: 15 Jul 2005 Posts: 89 Location: UK
|
Problem printing leading zeros using %w |
Posted: Wed Jun 27, 2007 3:36 am |
|
|
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 |
|