RtPrintf
RtPrintf prints formatted output to the standard output stream or console window.
Syntax
INT RtPrintf(
LPCSTR lpFormat [,argument, . . .]
);
Parameters
lpFormat
The format control (with optional arguments).
Return Value
If the function succeeds, it returns the number of characters printed. If an error occurs, it returns a negative value.
Remarks
RtPrintf is like printf, but RtPrintf does not require the C Runtime library and can work with any combination of run-time libraries. This function does not support floating point conversions in the Process environment.
RtPrintf/RtWprintf only write to the eRTOS Console (never to stdout). If you redirect stdout to a file with freopen, RtPrintf/RtWprintf will continue to write to the eRTOS Console, but printf/wprintf and their related APIs will write to the file.
If arguments follow the format string, the format string must contain specifications that determine the output format for the arguments.
The format argument consists of ordinary characters, escape sequences, and (if arguments follow format) format specifications. The ordinary characters and escape sequences are copied in order of appearance.
Format specifications always begin with a percent sign (%) and are read left to right. When RtPrintf encounters the first format specification (if any), it converts the first argument's value after format and outputs it accordingly. The second format specification causes the second argument to be converted and output, and so on. If there are more arguments than there are format specifications, the extra arguments are ignored. The results are undefined if there are not enough arguments for all the format specifications.
Example
RtPrintf("Line one\n\t\tLine two\n");
produces the output:
Line one
Line two
Format Specification Fields (RtPrintf and RtWprintf)
A format specification consists of optional and required fields and has the following form:
%[flags] [width] .precision] [{h|l|L}]type
Each field of the format specification is a single character or number signifying a particular format option. The simplest format specification contains only the percent sign and a type character (for example, %s). If a percent sign is followed by a character with no meaning as a format field, the character is copied. For example, to print a percent-sign character, use %%.
Required format field: The type character appears after the optional format fields and is the only required format field. It determines whether the associated argument is interpreted as a character, a string, or a number, as shown in the following table.
Note: The types C and S, and their behavior of c and s with RtPrintf and RtWprintf are consistent with Microsoft extensions for printf and are not ANSI compatible.
Type character | Argument | Output format |
---|---|---|
%% | A literal '%' character | |
%c |
Integer |
For RtPrintf: specifies a single-byte character. For RtWprintf: specifies a wide character. |
%d | Integer |
Signed decimal integer. |
%u | Integer |
Unsigned decimal integer. |
%x | Integer |
Unsigned hexadecimal integer, using "abcdef." |
%e | Floating-point |
Not supported |
%E | Floating-point | Not supported |
%f | Floating-point | Signed value that has the form [-]dddd.dddd, where dddd is one or more decimal digits |
%F | Floating-point | Not supported |
%g | Floating-point | Not supported |
%G | Floating-point | Not supported |
%a | Floating-point | Not supported |
%A | Floating-point | Not supported |
%s |
String |
For RtPrintf: specifies a single-byte character string. For RtWprintf: specifies a wide character string. Characters are printed up to the first null character or until the precision value is reached. |
%o |
Integer |
Not supported |
%p |
Pointer Type |
Not supported |
%z |
ANSI_STRING or UNICODE_STRING structure |
Not supported |
%wz |
UNICODE_STRING structure |
Not supported |
%I64d (and others like this, such as U64) |
Integer |
Not supported |
The optional fields, which appear before the type character, control other aspects of the formatting, as listed below.
flags
Optional character(s) that control justification of output and print of signs, blanks, decimal points, and octal and hexadecimal prefixes. More than one flag can appear in a format specification.
width
Optional number that specifies the minimum number of characters.
precision
Optional number that specifies the maximum number of characters printed for all or part of the output field or the minimum number of digits printed for integer values.
H|l| L
Optional prefixes to type that specify the size of the argument.
Requirements
Minimum supported version | Header | Library |
---|---|---|
eRTOS 1.0 SDK |
Rtapi.h | rtkrnl.lib |
See Also: