【 在 cainaonao (这些记号用用就熟悉了) 的大作中提到: 】
— Function: int sprintf (char *s, const char *template, ...)
This is like printf, except that the output is stored in the character
array s instead of written to a stream. A null character is written to
mark the end of the string.
The sprintf function returns the number of characters stored in the
array s, not including the terminating null character.
The behavior of this function is undefined if copying takes place
between objects that overlap—for example, if s is also given as an
argument to be printed under control of the `%s' conversion.
See Copying and Concatenation.
Warning: The sprintf function can be dangerous because it can
potentially output more characters than can fit in the allocation size
of the string s. Remember that the field width given in a conversion
specification is only a minimum value.
To avoid this problem, you can use snprintf or asprintf, described
— Function: int snprintf (char *s, size_t size, const char *template, ...)
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.
【 在 saphires (萝卜) 的大作中提到: 】