Embedded TCP/IP stack  4.7.0

◆ fnet_sprintf()

fnet_size_t fnet_sprintf ( fnet_char_t str,
const fnet_char_t format,
  ... 
)

Print formatted text to the buffer.

Parameters
strPointer to buffer where the resulting string is stored.
formatFormat string.
Returns
This function returns the number of characters that were successfully written, excluding the trailing null.
See also
fnet_snprintf()

The format string contains the text to be written to the str buffer. The optional arguments following format are items (integers, characters or strings) that are to be converted to character strings and inserted into the output of format at specified placeholders. The number of arguments following the format parameters should at least be as much as the number of format placeholders.
The syntax for a format placeholder is "%[Flags][Width][Length]Type".

  • Flags can be omitted or be any of:
    • - : Left justify.
    • + : Right justify.
    • 0 : Pad with leading zeros.
    • space : Print space if no sign.
  • Width is minimum field width. It can be omitted.
  • Length is conversion character. It can be omitted or by any of:
    • h : Short integer.
    • l : Long integer.
  • Type can by any of:
    • d, i : Integer.
    • u : Unsigned.
    • x, X : Hexadecimal.
    • o : Octal.
    • b : Binary.
    • p : Pointer.
    • c : Single char.
    • s : Char string.
    • n : Nothing.

The fnet_sprintf() function is just like fnet_printf(), except that the output is sent to buffer.

This function does not check the bounds of the buffer and therefore creates the risk of a buffer overflow. It is recommended to use fnet_snprintf() that doesn't suffer from buffer overruns.

Note
To save some bytes from all the hard coded strings the fnet_(s)printf() functions will expand all line feeds ("\n") inside the format string to CR LF ("\r\n"). So do not use "\r\n" in the format string - it will be expanded to "\r\r\n". It is save to add it via a parameter though, e.g. fnet_printf("%s", "\r\n");
This feature can be disable/enabled by the FNET_CFG_SERIAL_PRINTF_N_TO_RN configuration parameter.

© 2005-2020 by Andrej Butok. http://fnet.sourceforge.net