字符串格式化命令,主要功能是把格式化的数据写入某个字符串中。sprintf 是个变参函数。
|
1
|
/*例子*/ |
|
1
2
3
4
5
6
7
8
9
10
11
|
#include<stdio.h>/*某个stdio.h*/int main()/*主函数“整数”类型*/{ char buffer[50];/*“字符”类型的数组,下面共有50个元素。*/ int n,a=5,b=3;/*三个变量都为“整数”类型,intn中间要有空格*/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 3 is 8] is a string 13 chars long
|
原文:http://www.cnblogs.com/bohaoist/p/4622584.html