From fd1109a25f3c9b9eecb34b1478eea1536e2986c3 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 1 Sep 2019 22:18:00 +0200 Subject: [PATCH] mescc: Mes C Library: vfprintf, vsnprintf: Pad floats with space. * lib/stdio/vfprintf.c (vfprintf): Pad floats with space. * lib/stdio/vsnprintf.c (vsnprintf): Pad floats with space. * lib/tests/stdio/90-sprintf.c: Test it. --- lib/stdio/vfprintf.c | 2 +- lib/stdio/vsnprintf.c | 2 +- lib/tests/stdio/90-sprintf.c | 16 +++++++++++++--- lib/tests/stdio/90-sprintf.stdout | 7 ++++++- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/lib/stdio/vfprintf.c b/lib/stdio/vfprintf.c index 9de972ad..979ad8df 100644 --- a/lib/stdio/vfprintf.c +++ b/lib/stdio/vfprintf.c @@ -204,7 +204,7 @@ vfprintf (FILE * f, char const *format, va_list ap) } while (precision > length) { - fputc ('0', f); + fputc (' ', f); precision--; width--; count++; diff --git a/lib/stdio/vsnprintf.c b/lib/stdio/vsnprintf.c index 8b99ff58..a8d9624d 100644 --- a/lib/stdio/vsnprintf.c +++ b/lib/stdio/vsnprintf.c @@ -222,7 +222,7 @@ vsnprintf (char *str, size_t size, char const *format, va_list ap) while (precision > length) { if (count < size) - *str++ = '0'; + *str++ = ' '; precision--; width--; count++; diff --git a/lib/tests/stdio/90-sprintf.c b/lib/tests/stdio/90-sprintf.c index 2401195d..cbbd8918 100644 --- a/lib/tests/stdio/90-sprintf.c +++ b/lib/tests/stdio/90-sprintf.c @@ -18,7 +18,7 @@ * along with GNU Mes. If not, see . */ -#include +#include #include #include @@ -26,8 +26,18 @@ int main () { char buf[20]; - double d = 0; - sprintf (buf, "%.6g", d); + + int i = 0; + printf ("%3.6d\n", i); + sprintf (buf, "%3.6d", i); + puts (buf); + + double d = 1; + printf ("%3.6f\n", d); + sprintf (buf, "%3.6f", d); + puts (buf); + printf ("%3.6g\n", d); + sprintf (buf, "%3.6g", d); puts (buf); return 0; diff --git a/lib/tests/stdio/90-sprintf.stdout b/lib/tests/stdio/90-sprintf.stdout index 573541ac..ff6ae31d 100644 --- a/lib/tests/stdio/90-sprintf.stdout +++ b/lib/tests/stdio/90-sprintf.stdout @@ -1 +1,6 @@ -0 +000000 +000000 +1.000000 +1.000000 + 1 + 1