## printf

#### OS/161 Reference Manual

### Name

printf - print formatted output

### Library

Standard C Library (libc, -lc)

### Synopsis

#include <stdio.h>
int
printf(const char *format, ...);

### Description

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 int)
> d | Signed integer printed in decimal
> o | Unsigned integer printed in octal
> p | Pointer (void *)
> s | String (const char *)
> u | Unsigned integer printed in decimal
> x | Unsigned integer printed in hexadecimal
> X | Unsigned integer 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.
> 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.

### Restrictions

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 `+' and ` ' modifiers.

### Return Values

printf returns the number of characters printed.