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:
parent
e930a00a35
commit
76729c9971
|
@ -206,7 +206,7 @@ vfprintf (FILE* f, char const* format, va_list ap)
|
|||
}
|
||||
while (precision > length)
|
||||
{
|
||||
fputc ('0', f);
|
||||
fputc (' ', f);
|
||||
precision--;
|
||||
width--;
|
||||
count++;
|
||||
|
|
|
@ -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++;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1 +1,6 @@
|
|||
0
|
||||
000000
|
||||
000000
|
||||
1.000000
|
||||
1.000000
|
||||
1
|
||||
1
|
||||
|
|
Loading…
Reference in New Issue