Sprintf

From Pinguino
Jump to: navigation, search

Name

sprintf - store printf output to string variable.

Description

Composes a string with the same text that would be printed if format was used on Printf, but instead of being printed, the content is stored as a C string.

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.

Since
Beta 9.5

Syntax

Sprintf(char * buffer, char * format, args, ...); Formatted string is stored in a C-string pointed by buffer.

Example

u8 buffer[80];

void setup()
{
	// wait for a key to start
	while (CDC.getKey() != '\r');
}

void loop()
{
	Sprintf(buffer, "My name is Bond, %s Bond.\n\r", "James");
	CDC.printf("%s", buffer);
}


Output on USB CDC port : My name is Bond, James Bond.

Bugs

See also

Printf for all supported formats.
Sprintf

CDC.getString        CDC.print        CDC.printf
CDC.println          CDC.read         CDC.write
CDC.getKey

Serial.getString     Serial.print     Serial.printf
Serial.println       Serial.read      Serial.write

lcd.print

Comments