snprint原型:
int snprintf(char *str, size_t size, const char *format, ...);
The functions snprintf() and vsnprintf() write at most size bytes (including the terminating null byte (‘\0’)) to str.
函数snprintf最多可以写size个字节到str中’(包括\0’)
现在一起做个实验:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
int ret = 0;
char *buf = malloc(10);
if(!buf)
{
printf("malloc failed!\n");
exit(1);
}
memset(buf, 0, 10);
ret = snprintf