Performs formatted output to a string in memory.
#include <stdio.h> int sprintf (char *str, const char *format_spec, . . . );
If no conversion specifications are given, you may omit the output sources. Otherwise, the function calls must have at least as many output sources as there are conversion specifications, and the conversion specifications must match the types of the output sources.
Conversion specifications are matched to output sources in left-to- right order. Excess output pointers, if any, are ignored.
#include <stdio.h> main() { int temp = 4, temp2 = 17; char s[80]; sprintf(s, "The answers are %d, and %d.", temp, temp2); }
In this example, character string s has the following contents:
The answers are 4, and 17.
For a complete description of the format specification and the output source, see Chapter 2.
x | The number of characters placed in the output string, not including the final null character. |
Negative value | Indicates an output error occurred. The function sets errno. For a list of errno values set by this function, see fprintf in this section. |