Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zero padding disabled when precision specified #131

Closed
Iangitpers opened this issue Dec 11, 2021 · 3 comments
Closed

Zero padding disabled when precision specified #131

Iangitpers opened this issue Dec 11, 2021 · 3 comments

Comments

@Iangitpers
Copy link

An issue I've noticed:
c=29;
printf("%03.u", c);
Output: " 29"
Expected "029"

In v4 around line 724:

       // ignore '0' flag when precision is given
        if ((flags & FLAGS_PRECISION)) {
          flags &= ~FLAGS_ZEROPAD;
        }

A hack:


       // ignore '0' flag when precision is given
        //HACK: we want the leading 0s with precision....
        if ((flags & FLAGS_PRECISION) && (*format != 'u')) {
          flags &= ~FLAGS_ZEROPAD;
        }
@mickjc750
Copy link

"%03.u"
You have specified the 0 flag and a width of 3, followed by an incomplete precision (no digits after the .)
Standard behavior is to ignore the 0 flag when precision is specified.
If you want a precision of 3, your string should be "%.3u", if you want a width of 3, your string should be "%03u", both will produce the same output for unsigned integer types.
This repo is no longer maintained. If you want a fixed version of this repo, take a look at https://github.com/eyalroz/printf
If you want something more lightweight, you may like https://github.com/mickjc750/prnf

@eyalroz
Copy link

eyalroz commented Dec 12, 2021

@Iangitpers : You'll want to close this issue...

@Iangitpers
Copy link
Author

Thank you. I see that this is my error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants