snprintf()函数返回值
【推荐阅读】微服务还能火多久?>>> 函数原型: int snprintf(char *str, size_t size, const char *format, ...); size 的作用就是限制往str写入不超过size个字节(包括了结尾的'\0')。 因为sprintf()函数如果成功的话,返回成功写入的字节数(字符数),我就一直以为snprintf()函数也是如此,也就是snprintf()函数不会返回大于size的整数。 看下面一段手册内容: The functions snprintf() and vsnprintf() do not write more than size bytes (including the trailing ’\0’). If the output was truncated due to this limit then the return value is the number of characters (not including the trailing ’\0’) which would have been written to the final string if enough space had been available. Thus, a return value of size or more means that