Printf

Name
printf - print formatted string

Description
Printf functions (Serial.printf, CDC.printf, lcd.printf, ...) send a formatted string to the current output.

It uses printf.c, a new implementation of the stdlib library (stdlib.c).

This new library provides simple, small and low footprint printf functionality for use in embedded systems.

The formats supported by this implementation are: 'd' 'u' 'b' 'o' 'c' 's' 'x' 'X' and 'f'.

Zero padding and field width are also supported.

Formats

 * 'd' signed int

Serial.printf("i = %d\n", -128);


 * Output on serial port : i = -128


 * 'u' unsigned int

lcd.printf("i = %u\n", 1024);


 * Output on LCD display : i = 1024


 * 'b' binary

CDC.printf("i = %b\n", 1024);


 * Output on USB CDC (serial emulation) port : i = 010000000000


 * 'o' octal

Serial.printf("i = %o\n", 1024);


 * Output on default serial port : i = 2000


 * 'x' lower case hexadecimal

lcd.printf("i = %x\n", 8191);


 * Output on LCD display : i = 1fff


 * 'X' upper case hexadecimal

CDC.printf("i = %X\n", 8191);


 * Output on USB CDC port : i = 1FFF


 * 'c' ASCII character

Serial.printf("c = %c\n", 65);


 * Output on serial port : c = A


 * 's' string

lcd.printf("My name is %s, James Bond\n", "Bond");


 * Output on LCD display : My name is Bond, James Bond


 * 'f' float

CDC.printf("i = %f\n", 3.14);     // 2 digits after decimal comma by default CDC.printf("i = %.1f \r\n", 3.14); // 1 digit after decimal comma


 * Output on USB CDB port : i = 3.14 or i = 3.1

Zero padding and field width
See example below for Serial output.

Bugs
On 8-bit PIC with X.4 rev.685, 'pad' and 'justify' directives seem not to work.

Comments
Since: Beta 9.5