说明:xprintf表示printf系列的函数。
The format string is a character string, beginning and ending in its initial shift state, if any.
The format string is composed of zero or more directives:
格式说明串主要包含两部分,普通字符和转换说明符
1. ordinary characters (not %), which are copied unchanged to the output stream;
普通字符直接输出
2. conversion specifications, each of which results in fetching zero or more subsequent arguments.
Each conversion specification is introduced by the character %, and ends with a conversion specifier.
转换说明符形如%d,可能需要0个或多个后序参数
"% [flags ...] [minimum field width] [precision] [length modifier] conversion-specifications"
-
[flags ...]
-
# 加前缀,o->0, x->0x
-
0 converted value is padded on the left with zeros rather than blanks.
-
- The converted value is to be left adjusted on the field boundary.
-
' ' A blank should be left before a positive number (or empty string) produced by a signed conversion.
-
+ A sign (+ or -) should always be placed before a number produced by a signed conversion.
-
-
[minimum field width]
如果结果位宽不足,则用空格填充;如果位宽超过限制也不会造成结果被截断,而是忽略位宽限制
-
[precision]
-
格式为.[num],如果只有小数点则取精度为0;负数忽略该限制;
-
This gives the minimum number of digits to appear for d, i, o, u, x, and X conversions
-
This gives the number of digits to appear after the radix character for a, A, e, E, f, and F conversions
-
the maximum number of significant digits for g and G conversions
-
the maximum number of characters to be printed from a string for s and S conversions.
-
-
[length modifier]
-
hh --> char
-
h --> short int
-
l --> long int
-
ll --> long long int
-
L --> long double
-
z --> sizt_t
-
t --> ptrdiff_t
-
-
conversion specifications (A character that specifies the type of conversion to be applied. )
-
d,i : int --> signed decimal
-
o,u,x,X : unsigned int --> unsigned octal,hexadecimal
-
e,E: The double argument is rounded and converted in the style [-]d.ddde±dd
-