Formatting Text for Output

Describes conversion specifiers used for formatting text for output. The printf() function and its related functions accept a formatting argument. This argument specifies how to format the arguments that follow it. The formatting argument points to a character string containing normal text and conversion specifications. The formatting functions send normal text directly to output. The functions replace conversion specifications with formatted text based on matching arguments passed to the functions. Conversion specifications must have matching arguments in the same order in which they occur in the formatting string.

A conversion specification describes type of character representation its associated argument is to be converted to. A conversion specification contains these characters, in order from left to right:

A conversion specification's characters must not be separated by white space. Doubling the percent sign (%%) results in the output of a single %.

After the initial percent sign, optional flags modify the formatting of the argument; the argument can be left- or right-justified, and numerical values can be padded with zeroes or output in alternate forms. More than one flag character may appear in a conversion specification.The following table describes the flag characters.

The optional minimum width is a decimal digit string. If the converted value has more characters that the minimum width, it is expanded as required. If the converted value has fewer characters than the minimum width, it is, by default, right justified (padded on the left). If the - flag character is used, the converted value is left justified (padded on the right). The maximum value that EWL allows is 509.

The optional precision width is a period character (.) followed by decimal digit string. The default precision is 6 digits after the decimal point. For floating point values, the precision width specifies the number of digits to print after the decimal point. For integer values, the precision width works the same as, and cancels, the minimum width specification. When used with a character array, the precision width indicates the maximum width of the output.

A minimum width and a precision width can also be specified with an asterisk (*)instead of a decimal digit string. An asterisk indicates that there is a matching argument, preceding the conversion argument, specifying the minimum width or precision width.

An optional conversion modifier specifies additional information about the corresponding argument's type or size. These characters appear before the conversion specifier. The table below describes these conversion modifiers.

The terminating characters, the conversion type, specify the conversion to apply to the matching argument. The table below describes the conversion types.
Table 1. Flags for Modifying Conversion Specifies
Character Description
- The conversion will be left-justified. By default, arguments are right-justified.
+ The conversion, if numeric, will be prefixed with a sign (+ or -). By default, only negative numeric values are prefixed with a minus sign (-).
space If the first character of the conversion is not a sign character, it is prefixed with a space. Because the plus sign flag character (+) always prefixes a numeric value with a sign, the space flag has no effect when combined with the plus (+) flag.
# For c, d, i, and u conversion types, this flag has no effect. For s conversion types, the matching argument is considered to be a pointer to a Pascal string and is output as a character string. For o conversion types, this flag prefixes the conversion with a 0. For x conversion types, the conversion is prefixed with a 0x. For e, E, f, g, and G conversions, this flag forces a decimal point in the output. For g and G conversions, trailing zeroes after the decimal point are not removed.
0 This flag pads zeroes on the left of the conversion. It applies to d, i, o, u, x, X, e, E, f, g, and G conversion types. The leading zeroes follow sign and base indication characters, replacing what would normally be space characters. The minus sign flag character overrides the 0 flag character. The 0 flag is ignored when used with a precision width for d, i , o, u, x, and X conversion types.
@ AltiVec: This flag indicates a pointer to a string specified by an argument. This string will be used as a separator for vector elements
The table below describes these conversion modifiers.
Table 2. Specifying the Size or Type of an Argument
Character Description
h The following d, i, o, u, x, X or n conversion will be stored in an object of type short int or unsigned short int.
l The lower case l followed by d, i, o, u, x, or X conversion specifier indicates the argument is a long int or unsigned long int. The lower case L followed by a c conversion specifier, indicates that the argument is of type wint_t. The lower case L followed by an s conversion specifier, indicates that the argument is of type wchar_t.
ll The double l followed by d, i, o, u, x, or X conversion specifier indicates the argument is a long longor unsigned long long.
L The upper case L followed by e, E, f, g, or G conversion specifier indicates a long double.
v An AltiVecvector of type bool char, signed char, or unsigned char when followed by c, d, i, o, u, x, or X. A vector of type float, when followed by f.
vh or hv An AltiVecvector of type short, short bool, bool short, or pixel when followed by c, d, i, o, u, x, or X.
vl or lv An AltiVecvector of type int, unsigned in, or bool intwhen followed by c, d, i, o, u, x, or X.
The table below lists the conversion types.
Table 3. Specifying the Type of Conversion
Character Conversion
c A character.
d or i A signed decimal number.
e or E The floating point argument (of type floator double) is output in scientific notation. This specifier places one digit before the decimal point and appends a representation of a base-10 exponent. If the precision width is 0, no decimal point is output. The exponent value is at least 2 digits long. The e conversion type uses lowercase e as the exponent prefix. The E conversion type uses uppercase E as the exponent prefix.
f or F The corresponding floating point argument (of type float or double) is printed in decimal notation. If the precision width is 0, the decimal point is not printed. For the f conversion specifier, an argument of type double that contains infinity produces inf. A double argument representing the not-a-number value produces nan. The F conversion specifier uses uppercase letters, producing INF and NAN instead.
g or G The g conversion type uses the f or e conversion types and the G conversion type uses the F or E conversion types. Conversion type e (or E) is used only if the converted exponent is less than -4 or greater than the precision width. The precision width indicates the number of significant digits. No decimal point is output if there are no digits following it.
n Stores the number of items output by the function so far. Its corresponding argument must be a pointer to an int.
o An unsigned octal.
p A pointer. The argument is output using the X conversion type format.
s A character string. The corresponding argument must be a pointer to a nul terminated character string. The nul character is not output.
#s A character string. The corresponding argument is a pointer to Pascal character string. A Pascal string is a length byte followed by the number of characters specified by the length byte. This conversion type is an extension to the ISO/IEC standards.
u An unsigned hexadecimal. The lowercase x uses lowercase letters (abcdef) while uppercase X uses uppercase letters (ABCDEF).
x or X An unsigned hexadecimal.