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.
This commit is contained in:
Jan Nieuwenhuizen 2019-09-01 22:18:00 +02:00
parent f097a9d270
commit fd1109a25f
No known key found for this signature in database
GPG key ID: F3C1A0D9C1D65273
4 changed files with 21 additions and 6 deletions

View file

@ -204,7 +204,7 @@ vfprintf (FILE * f, char const *format, va_list ap)
} }
while (precision > length) while (precision > length)
{ {
fputc ('0', f); fputc (' ', f);
precision--; precision--;
width--; width--;
count++; count++;

View file

@ -222,7 +222,7 @@ vsnprintf (char *str, size_t size, char const *format, va_list ap)
while (precision > length) while (precision > length)
{ {
if (count < size) if (count < size)
*str++ = '0'; *str++ = ' ';
precision--; precision--;
width--; width--;
count++; count++;

View file

@ -18,7 +18,7 @@
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <libmes.h> #include <mes/lib.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -26,8 +26,18 @@ int
main () main ()
{ {
char buf[20]; 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); puts (buf);
return 0; return 0;

View file

@ -1 +1,6 @@
0 000000
000000
1.000000
1.000000
1
1