OS/161 Reference Manual


printf - print formatted output


Standard C Library (libc, -lc)


#include <stdio.h>

printf(const char *format, ...);


printf prints formatted text to standard output. The text is generated from the format argument and subsequent arguments according to the following rules.

Characters in format that are not the percent sign ( %) are printed verbatim. When a percent sign is encountered, the next argument of the arguments following format is retrieved and printed. The type of the argument expected, as well as some simple formatting instructions, are derived from the characters following the percent sign.

The following characters designate types to print. One of these characters concludes the format sequence begun with a percent sign, and also determines the type expected as an argument.

% A percent sign is printed; no argument is consumed.
c Character (char, passed as an integer value)
d Signed integer value printed in decimal
o Unsigned integer value printed in octal
p Pointer (void *)
s String (const char *)
u Unsigned integer value printed in decimal
x Unsigned integer value printed in hexadecimal
X Unsigned integer value printed in uppercase hex

The following characters are modifiers; they can be found between the percent sign and the type designator.

# Select an "alternate format". On integer formats this causes the C base prefix to be printed along with the integer. On other formats, this has no effect.
l Assume an integer argument is long or unsigned long instead of int or unsigned int. If repeated, the argument is taken to be long long or unsigned long long.
z Assume an integer argument is ssize_t or size_t instead of int or unsigned int.
0-9 Digits are treated as a decimal number, which is considered to be the field width. The argument is printed right-aligned in a field that many characters wide.
0 If the field width has a leading 0, the padding character for alignment is made 0 (zero) instead of space.
- If a field width is given, use it for left alignment instead of right alignment.


Note that this is a limited printf implementation - it has no support for precisions (".number" as a modifier), floating-point formats, field widths passed as arguments, or the rarely-used plus and space modifiers.

Return Values

printf returns the number of characters printed.