C Tutorial/printf scanf/printf Justify


Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179

Deprecated: Creation of dynamic property PPDStack::$accum is deprecated in /var/www/cppe.ru/www/includes/parser/Preprocessor_DOM.php on line 803

Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179

Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/vendor/mediawiki/at-ease/src/Functions.php on line 48
Материал из C\C++ эксперт
Перейти к: навигация, поиск

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