原文地址:
http://www.cplusplus.com/reference/cstdio/sprintf/
/* sprintf example */
#include <stdio.h>
int main()
{
char buffer[50];
int n, a = 5, b = 4;
//buffer要存储后面format的字符串,返回的结果是字符串的长度
n = sprintf(buffer, "%d plus %d is %d", a, b, a + b);
printf("[%s] is a string %d chars long\n", buffer, n);
return 0;
//输出结果:[5 plus 4 is 9] is a string 13 chars long
}