Write text in specified format to SFR
int __far printf(const char __far *format, ...);
int __far printf_tiny(const char __far *format, ...);
The number of characters that were output (excluding the null character (\0)) is returned.
Returns EOF(-1) if a write error has occurred.
This function converts the arguments following format to match the output format, and outputs them to SFR using the putchar function. The conversion method in this case complies with the format specified by the string indicated by format.
Correct operation is not guaranteed if there is not enough arguments to satisfy the format. If the format becomes full even though arguments are still left, the extra arguments are merely evaluated and they will be ignored.
The format consists of 0 or more directives. The format will be output without change except for a conversion specification starting with %. The conversion specification fetches the 0 or more subsequent arguments, converts them, and then outputs them.
The format consists of the following two types of directives:
Characters that are copied directly without conversion (other than "%"). |
|
Specifications that fetch zero or more arguments and assign a specification. |
Each conversion specification begins with character "%" (to insert "%" in the output, specify "%%" in the format string). The following appear after the "%":
%[flag][field-width][precision][size][type-specification-character]
The meaning of each conversion specification is explained below.
Zero or more flags, which qualify the meaning of the conversion specification, are placed in any order.
The flag characters and their meanings are as follows:
This is an optional minimum field width.
If the converted value is smaller than this field width, the left side is filled with spaces (if the left justification flag explained above is assigned, the right side will be filled with spaces). This field width takes the form of "*" or a decimal integer. If "*" is specified, an int type argument is used as the field width. A negative field width is not supported. If an attempt is made to specify a negative field width, it is interpreted as a minus (-) flag appended to the beginning of a positive field width.
For d, i, o, u, x, or X conversion, the value assigned for the precision is the minimum number of digits to appear. For e, f, or E conversion, it is the number of digits to appear after the decimal point. For g or G conversion, it is the maximum number of significant digits. For s conversion, it is the maximum number of bytes.
The precision takes the form of "*" or "." followed by a decimal integer. If "*" is specified, an int type argument is used as the precision. If a negative precision is specified, it is treated as if the precision were omitted. If only "." is specified, the precision is assumed to be 0. If the precision appears together with a conversion specification other than the above, the operation is undefined.
This is an arbitrary optional size character h, l, ll, or L, which changes the default method for interpreting the data type of the corresponding argument.
When h is specified, a following d, i, o, u, x, or X type specification is forcibly applied to a short int or unsigned short int argument. h is also causes a following n type specification to be forcibly applied to a pointer to short argument.
When l is specified, a following d, i, o, u, x, or X type specification is forcibly applied to a long or unsigned long argument. l is also causes a following n type specification to be forcibly applied to a pointer to long argument.
When ll is specified, a following d, i, o, u, x, or X type specification is forcibly applied to a long long and unsigned long long argument. Furthermore, for ll, a following n type specification is forcibly applied to a long long pointer.
When L is specified, a following e, E, f, g, or G type specification is forcibly applied to a long double argument. However, since the double type and long double type have the same format in this compiler, the specification has no effect.
These are characters that specify the type of conversion that is to be applied.
The characters that specify conversion types and their meanings are as follows.
printf_tiny is a simplified version of printf.
When macro __PRINTF_TINY__ is defined before the -D option or stdio.h is included, the function call of printf is replaced with printf_tiny. The following restrictions apply to conversion specifications of printf_tiny.