sprintf

Arguments:

String format, String source.

Result:

String.

Usage:

Forms a source in accordance with the provided format.

Format Specifier

The format parameter can contain format specifiers that begin with %. These specifiers are replaced by the values of respective variables that follow the format string.

A format specifier has the following parts:

The general prototype of format specifier for sprintf() is:

%[flags][width][.precision][length]specifier

Commonly Used Format Specifiers

The table below lists some commonly used format specifiers:

Format Specifier Description
% a % followed by another % character prints % to the screen
c writes a single character
s writes a character string
d or i converts a signed integer to decimal representation
o converts an unsigned integer to octal representation
X or x converts an unsigned integer to hexadecimal representation
u converts an unsigned integer to decimal representation
F or f converts floating-point number to the decimal representation
E or e converts floating-point number to the decimal exponent notation
A or a converts floating-point number to the hexadecimal exponent
G or g converts floating-point number to either decimal or decimal exponent notation
n - returns the number of characters written so far
- the result is written to the value pointed to by the argument
- the argument must be a pointer to signed int
p writes an implementation-defined character sequence defining a pointer