Site Tools
Sidebar
User's Manual
t2:printf
printf
printf — Output a formatted string
Description
void printf(char *fmt, ...);
Print a formatted string to Gtuner IV output.
Parameters
- fmt: The string that contains the text to be printed. It can optionally contain embedded format tags that are replaced by the values specified in subsequent additional arguments and formatted as requested.
- args: Depending on the fmt string, the function may expect a sequence of additional arguments, each containing one value to be inserted in place of each
%-tag
specified in the format parameter. There should be the same number of these arguments as the number of%-tags
that expect a value.
Return Value
No value is returned.
Format Tag Syntax
The format tag prototype is: %[flags][width][.precision][length]specifier
flags | |
---|---|
- | Left-justify within the given field width. Right justification is the default. |
+ | Forces to precede the result with a plus or minus sign even for positive numbers. |
# | Used with o, x or X specifiers the value is preceded with 0, 0x or 0X respectively for values different than zero. Used with e, E and f, it forces the written output to contain a decimal point even if no digits would follow. |
0 | Left-pads the number with zeroes instead of spaces, where padding is specified. |
width | |
number | Minimum number of characters to be printed. |
* | The width is not specified in the format string, but as an additional integer value argument preceding the argument that has to be formatted. |
.precision | |
.number | For integer specifiers (d, i, o, u, x, X), precision specifies the minimum number of digits to be written. For e, E and f specifiers, this is the number of digits to be printed after the decimal point. |
.* | The precision is not specified in the format string, but as an additional integer value argument preceding the argument that has to be formatted. |
length | |
h | The argument is interpreted as a short int or unsigned short int. |
l | The argument is interpreted as a long int or unsigned long int. |
specifier | |
c or C | Character. |
d or i | Signed decimal integer. |
e | Scientific notation using e character. |
E | Scientific notation using E character. |
f | Decimal point. |
g | Uses the shorter of %e or %f. |
G | Uses the shorter of %E or %f. |
o | Signed octal. |
s or S | Pointer address of the string. Note: This specifier does not have the conventional expected behavior. |
u | Unsigned decimal integer. |
x | Unsigned hexadecimal integer. |
X | Unsigned hexadecimal integer with capital letters. |
p | Pointer address. |
n | Nothing printed. |
% | The % character. |
Examples
Example #1 printf() example
init { int ch; for(ch=85; ch<=100; ++ch) { printf("ASCII: %d, Character: %c", ch, ch); } }
t2/printf.txt · Last modified: 2016/12/01 12:40 by J2Kbr