Skip to Content

c语言printf()输出格式控制

  • strict warning: Non-static method view::load() should not be called statically in /var/www/drupal_module/views/views.module on line 906.
  • strict warning: Declaration of views_handler_filter::options_validate() should be compatible with views_handler::options_validate($form, &$form_state) in /var/www/drupal_module/views/handlers/views_handler_filter.inc on line 0.
  • strict warning: Declaration of views_handler_filter::options_submit() should be compatible with views_handler::options_submit($form, &$form_state) in /var/www/drupal_module/views/handlers/views_handler_filter.inc on line 0.
  • strict warning: Declaration of views_handler_filter_node_status::operator_form() should be compatible with views_handler_filter::operator_form(&$form, &$form_state) in /var/www/drupal_module/views/modules/node/views_handler_filter_node_status.inc on line 0.
  • strict warning: Declaration of views_plugin_row::options_validate() should be compatible with views_plugin::options_validate(&$form, &$form_state) in /var/www/drupal_module/views/plugins/views_plugin_row.inc on line 0.
  • strict warning: Declaration of views_plugin_row::options_submit() should be compatible with views_plugin::options_submit(&$form, &$form_state) in /var/www/drupal_module/views/plugins/views_plugin_row.inc on line 0.
  • strict warning: Non-static method view::load() should not be called statically in /var/www/drupal_module/views/views.module on line 906.
  • strict warning: Non-static method view::load() should not be called statically in /var/www/drupal_module/views/views.module on line 906.
  • strict warning: Non-static method view::load() should not be called statically in /var/www/drupal_module/views/views.module on line 906.
  • strict warning: Declaration of views_handler_field_comment::init() should be compatible with views_handler_field::init(&$view, $options) in /var/www/drupal_module/views/modules/comment/views_handler_field_comment.inc on line 0.
  • strict warning: Declaration of views_handler_filter_boolean_operator::value_validate() should be compatible with views_handler_filter::value_validate($form, &$form_state) in /var/www/drupal_module/views/handlers/views_handler_filter_boolean_operator.inc on line 0.

awk,python等print的用法和C的printf的格式基本一样,时间长不用就会忘记,现将C语言printf输出格式备份如下:

1.printf 转换说明符

%a(%A) 浮点数、十六进制数字和p-(P-)记数法(C99)

%c 字符

%d 有符号十进制整数

%f 浮点数(包括float和doulbe)

%e(%E) 浮点数指数输出[e-(E-)记数法]

%g(%G) 浮点数不显无意义的零"0"

%i 有符号十进制整数(与%d相同)

%u 无符号十进制整数

%o 八进制整数 e.g. 0123

%x(%X) 十六进制整数0f(0F) e.g. 0x1234

%p 指针

%s 字符串

%% "%"

2.printf 标志

左对齐:"-" e.g. "%-20s"

右对齐:"+" e.g. "%+20s"

空格:若符号为正,则显示空格,负则显示"-" e.g. "% 6.2f"

#:对c,s,d,u类无影响;对o类,在输出时加前缀o;对x类,在输出时加前缀0x;

对e,g,f 类当结果有小数时才给出小数点。

3.格式字符串(格式)

[标志][输出最少宽度][.精度][长度]类型

"%-md" :左对齐,若m比实际少时,按实际输出。

"%m.ns":输出m位,取字符串(左起)n位,左补空格,当n>m or m省略时m=n

e.g. "%7.2s" 输入CHINA

输出" CH"

"%m.nf":输出浮点数,m为宽度,n为小数点右边数位

e.g. "%3.1f" 输入3852.99

输出3853.0

长度:为h短整形量,l为长整形量

 

-- EOF-TRUEVUE --