API Reference | developer.brewmp.com API Reference | developer.brewmp.com

Developer

API Reference

STD_SNPRINTF()

Brew Release
Brew MP 1.0.2
See Also
std_strlprintf()
Description

The functions std_snprintf() and std_vsnprintf() are similar to std_strlprintf and std_vstrlprintf that write formatted output to a string. Unlike std_strlprintf, std_snprintf also support the floating point conversion specifiers. These functions guarantee NUL-termination of the output buffer when its size is greater than zero.
A format string is copied to the output buffer, except for conversion specifiers contained within the format string. Conversion specifiers begin with a "%" and specify some action that consumes an argument from the argument list.
Conversion specifiers have the following form:
  
       %[FLAGS] [WIDTH] [.PRECISION] [TYPE] CONV


CONV is the only required field. It is always a single character, and determines the action to be taken. For a detailed description of conversion sepcifiers, please refer to the documentation of std_strlprintf(). Here. we only provide description of these fields as it applies to the additional CONV values supported by std_snprintf().
In addition to the values for CONV supported by std_strlprintf, this function supports the following values:
    CONV | Description
   ======|=======================================================
    e, E | Outputs a double value representing a floating point
         | number in the style [-]d.ddd e±dd, where there is one 
         | digit (which is nonzero if the argument is nonzero) 
         | before the decimal-point character and the number of
         | digits after it is equal to the precision. If the 
         | precision is missing, it is taken as 6. If the precision
         | is zero and the # flag is not specified, no decimal-point
         | character appears. The value is rounded to the appropriate
         | number of digits. The E conversion specifier produces a 
         | number with E instead of e introducing the exponent. The 
         | exponent always contains at least two digits, and only as 
         | many more digits as necessary to represent the exponent. 
         | If the value is zero, the exponent is zero.
         |
    f, F | Outputs a double value representing a floating point
         | number in the style [-]ddd.ddd, where the number of 
         | digits after the decimal-point character is equal to the 
         | precision specification. If the precision is missing, it 
         | is taken as 6. If the precision is zero and the # flag is
         | not specified, no decimal-point character appears. If a 
         | decimal-point character appears, at least one digit 
         | appears before it. The value is rounded to the appropriate 
         | number of digits.
         |
    g, G | Outputs a double value representing a floating point
         | number in the style f or e (or in style F or E in the case
         | of a G conversion specifier), with the precision specifying
         | the number of significant digits. If the precision is zero, 
         | it is taken as 1. The style used depends on the value 
         | converted. Style e (or E) is used only if the exponent 
         | resulting from such a conversion is less than -4 or greater 
         | than or equal to the precision. Trailing zeros are removed
         | from the fractional portion of the result unless the # flag 
         | is specified; a decimal-point character appears only if it 
         | is followed by a digit.
         |
    a, A | Outputs a double value representing a floating point
         | number in the style [-]0xh.hhhh p±d, where there is one 
         | non-zero hexadecimal digit before the decimal-point 
         | character and the number of hexadecimal digits after it is 
         | equal to the precision. If the precision is missing then 
         | the precision is assumed to be sufficient for an exact
         | representation of the value, except that trailing zeros 
         | may be omitted. If the precision is zero and the # flag is 
         | not specified, no decimal point character appears. The 
         | letters 'abcdef' are used for '%a' conversion and the 
         | letters ABCDEF for '%A' conversion. The '%A' conversion 
         | specifier produces a number with 'X' and 'P' instead of 'x' 
         | and 'p'. The exponent always contains at least one digit, 
         | and only as many more digits as necessary to represent the
         | decimal exponent of 2. If the value is zero, the exponent 
         | is zero.
         |

For 'e', 'f', 'g' and 'a' convervsion specifiers, a double argument representing an infinity is converted in to the style '[-]inf' and a double argument representing a NaN is converted in to the stlye 'nan'. The 'E', 'F', 'G' and 'A' conversion specifiers result in 'INF' or 'NAN' instead of 'inf' or 'nan', respectively.
Params
pszDest
[out]:
output buffer, where output will be placed
nDestSize
[]:
size of pszDest in bytes
pszFmt
[]:
format string
Interface
Prototype
  •    int std_snprintf(char *pszDest, int nDestSize, 
                        const char *pszFmt, ...);
Return

  • The size required to hold the entire untruncated output, NOT including NUL-termination.
Side Effect
  • None
Comments
Notable omissions from std_strlprintf() lack of support for "%n".