![]()  | 
   |
| << 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
formatto fill in the format parameters in the format stringthe types of arguments after
formatmatch the format fields informatthe 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 typeunsignedint)
%x hexadecimal integer (expects typesignedintorunsignedint)
%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_FLOATScan 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 |