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-02-06 21:18:00 +01:00
parent e930a00a35
commit 76729c9971
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
4 changed files with 20 additions and 5 deletions

View File

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

View File

@ -223,7 +223,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++;

View File

@ -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;

View File

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