C Tutorial/printf scanf/printf Justify
Версия от 14:21, 25 мая 2010; (обсуждение)
Flags
Flag characters are used to give directives for the output.
You can use multiple flag characters in any order.
- Indicates that output is left justified.
#include <stdio.h>
main()
{
printf("%-10.4d\n", 25);
printf("%10.4d\n", 25);
}
0025 0025
Right justifying and left justifying values
#include <stdio.h>
int main()
{
printf( "%10s%10d%10c%10f\n\n", "hello", 7, "a", 1.23 );
printf( "%-10s%-10d%-10c%-10f\n", "hello", 7, "a", 1.23 );
return 0;
}
hello 7 a 1.230000 hello 7 a 1.230000