<< Previous | Next >>

sprintf

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 to buffer (pointed to by buffer). The user should make sure that:

  • there are enough arguments after format to fill in the format parameters in the format string

  • the types of arguments after format match the format fields in format

  • 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 type unsigned int)
      %x   hexadecimal integer (expects type signed int or unsigned int)
      %s   a string (not interpreted, expects type (char *))
      %f   a float (expects type float)

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