<< Previous | Next >> | |
|
int sprintf( char * buffer, char * format, ... );
Description
- This function takes a string (pointed to by
format
), arguments of the format, and outputs the formatted string tobuffer
(pointed to bybuffer
). The user should make sure that:
there are enough arguments after
format
to fill in the format parameters in the format stringthe types of arguments after
format
match the format fields informat
the buffer is large enough to hold the longest possible formatted string
- The following is a short list of valid conversion specifiers in the format string. For a complete list of conversion specifiers, refer to the function description for printf.
- %d decimal integer (expects type
int
)
%u decimal unsigned integer (expects typeunsigned
int
)
%x hexadecimal integer (expects typesigned
int
orunsigned
int
)
%s a string (not interpreted, expects type (char
*
))
%f a float (expects typefloat
)
- For example,
sprintf(buffer,"%s = %x","variable x",256);
- puts the string "variable x = 100" into
buffer
.
- The macro
STDIO_DISABLE_FLOATS
can be defined if it is not necessary to format floating point numbers. If this macro is defined, %e, %f and %g will not be recognized. This can save thousands of bytes of code space.
- This function can be called by processes of different priorities.
Parameters
- buffer
- Result string of the formatted string.
- format
- String to be formatted.
- ...
- Format arguments.
Return Value
- Number of characters written.
Library
- STDIO.LIB
See also
- printf
Dynamic C Functions | << Previous | Next >> | rabbit.com |