Guardian C Library Calls Reference Manual

Reference to Library Calls
Guardian TNS C Library Calls Reference Manual128833 3-169
sprintf
sprintf
The sprintf function writes formatted data to a string.
str_ptr
points to the string where sprintf stores the formatted data.
format
points to a string that contains characters and conversion specifiers. Refer to
“fprintf” on page 3-51 for a description of format and conversion specifiers.
expr...
is the list of arguments to be formatted using the conversion specifiers in *format.
Return Value
is the number of characters output (not counting the null character) if the operation
is successful; otherwise, sprintf returns a negative value.
Usage Guidelines
To print a percent sign, you must precede it with a percent sign; for example:
sprintf(sp, "Stock went up %d%%\n", increase);
The sprintf function appends a null character to the output string.
When the converted sprintf argument has fewer characters than the specified field
width, sprintf uses blanks to pad out the extra space. To request padding with zeroes
instead of blanks, precede the field width with a zero.
Example
In this example, the sprintf function fetches an argument, formats it as a character string,
and stores it in an array of char:
#include <stdioh>
char sp[50];
char *x;
/* ... */
x = "Carolyn";
sprintf(sp, "Hello, %s", x);
#include <stdioh>
int sprintf(char *str_ptr, const char *format, [expr...]);