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 support@ccsinfo.com

printf, sprintf format

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



Joined: 02 Feb 2010
Posts: 345

View user's profile Send private message

printf, sprintf format
PostPosted: Mon Dec 31, 2018 3:52 am     Reply with quote

Hello,

I want to use %X.Yw printf format with leading zeros. Can I do this?

For Example:
Code:

unsigned int32 b = 12345;
printf("\r\nVar_b: %06.2lw", b);


Thanks!
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon Dec 31, 2018 4:38 am     Reply with quote

Yes,
However as posted, you won't get any zeros.

The count at the front of a C format specifier, is the _total field width_.
You are saying use 6 characters, with a decimal, and two trailing digits
So 123.45
This is six characters, so no space for a leading zero.

If you use: %09.2lw"

You will then get six digits in front of the decimal, so:

000123.45
kmp84



Joined: 02 Feb 2010
Posts: 345

View user's profile Send private message

PostPosted: Mon Dec 31, 2018 6:46 am     Reply with quote

Hi Mr."Ttelmah",

Š¢hanks for the fix! My mistake was that not counting '.' for character!

Best Wishes!
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon Dec 31, 2018 8:34 am     Reply with quote

That's quite a common slip... Very Happy

Happy New Year everyone.
kmp84



Joined: 02 Feb 2010
Posts: 345

View user's profile Send private message

PostPosted: Mon Dec 31, 2018 9:13 am     Reply with quote

Happy New Year and The Best Wishes! Surprised Wink
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