[chbot] Chchrobotics Digest, Vol 202, Issue 13

Bevin Brett bevin_brett at hotmail.com
Wed Jul 31 00:08:28 BST 2024


The cpp reference manual has a well-written description

https://cplusplus.com/reference/cstdio/snprintf/

int snprintf ( char * s, size_t n, const char * format, ... );

the content is stored as a C string in the buffer pointed by s (taking n as the maximum buffer capacity to fill).

Parameters

s
Pointer to a buffer where the resulting C-string is stored.
The buffer should have a size of at least n characters.
n
Maximum number of bytes to be used in the buffer.
The generated string has a length of at most
n-1
, leaving space for the additional terminating null character.
size_t<https://cplusplus.com/size_t> is an unsigned integral type.


As does the https://www.gnu.org/software/libc/manual/html_node/Formatted-Output-Functions.html

The snprintf function is similar to sprintf, except that the
size
 argument specifies the maximum number of characters to produce. The trailing null character is counted towards this limit, so you should allocate at least
size
 characters for the string
s
. If
size
 is zero, nothing, not even the null byte, shall be written and
s
 may be a null pointer.


Formatted Output Functions (The GNU C Library)<https://www.gnu.org/software/libc/manual/html_node/Formatted-Output-Functions.html>
Formatted Output Functions (The GNU C Library)
www.gnu.org



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ourshack.com/pipermail/chchrobotics/attachments/20240730/b66c58ef/attachment-0001.html>


More information about the Chchrobotics mailing list