int sprintf ( char * str, const char * format, ... );
Write formatted data to string
A terminating null character is automatically appended after the content.
參數
str
Pointer to a buffer where the resulting C-string is stored.
The buffer should be large enough to contain the resulting string.
format
C string that contains a format string that follows the same specifications as format in printf (see printf for details).
… (additional arguments)
Depending on the format string, the function may expect a sequence of additional arguments, each containing a value to be used to replace a format specifier in the format string (or a pointer to a storage location, for n).
return
On success, the total number of characters written is returned.
This count does not include the additional null-character automatically appended at the end of the string.
int snprintf ( char * s, size_t n, const char * format, ... );
Write formatted output to sized buffer
If the resulting string would be longer than n-1 characters, the remaining characters are discarded and not stored, but counted for the value returned by the function.
A terminating null character is automatically appended after the content written.
參數
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 is an unsigned integral type.
format
C string that contains a format string that follows the same specifications as format in printf (see printf for details).
… (additional arguments)
Depending on the format string, the function may expect a sequence of additional arguments, each containing a value to be used to replace a format specifier in the format string (or a pointer to a storage location, for n).