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
f097a9d270
commit
fd1109a25f
|
@ -204,7 +204,7 @@ vfprintf (FILE * f, char const *format, va_list ap)
|
|||
}
|
||||
while (precision > length)
|
||||
{
|
||||
fputc ('0', f);
|
||||
fputc (' ', f);
|
||||
precision--;
|
||||
width--;
|
||||
count++;
|
||||
|
|
|
@ -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++;
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <libmes.h>
|
||||
#include <mes/lib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
@ -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 a new issue