C Tutorial/printf scanf/printf Justify — различия между версиями
Admin (обсуждение | вклад) м (1 версия: Импорт контента...) |
|
(нет различий)
|
Версия 17: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.
<source lang="cpp">#include <stdio.h>
main()
{
printf("%-10.4d\n", 25); printf("%10.4d\n", 25);
}</source>
0025 0025
Right justifying and left justifying values
<source lang="cpp">#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;
}</source>
hello 7 a 1.230000 hello 7 a 1.230000