funciton sprintf
来源:互联网 发布:淘宝二手进口功放 编辑:程序博客网 时间:2024/05/29 09:51
function
<cstdio>
sprintf
int sprintf ( char * str, const char * format, ... );
Write formatted data to string
Composes a string with the same text that would be printed if format was used onprintf, but instead of being printed, the content is stored as aC string in the buffer pointed by str.
Composes a string with the same text that would be printed if format was used onprintf, but instead of being printed, the content is stored as aC string in the buffer pointed by str.
The size of the buffer should be large enough to contain the entire resulting string (seesnprintf for a safer version).
A terminating null character is automatically appended after the content.
After the format parameter, the function expects at least as many additional arguments as needed for format.
Parameters
- str
- Pointer to a buffer where the resulting C-string is stored.
The buffer should be large enough to contain the resulting string. - format
- C string that contains a format string that follows the same specifications as format inprintf (see printf for details).
- ... (additional arguments)
- Depending on the format string, the function may expect a sequence of additional arguments, each containing a value to be used to replace a format specifier in theformat string (or a pointer to a storage location, forn).
There should be at least as many of these arguments as the number of values specified in theformat specifiers. Additional arguments are ignored by the function.
Return Value
On success, the total number of characters written is returned. This count does not include the additional null-character automatically appended at the end of the string.On failure, a negative number is returned.
Example
1234567891011
/* sprintf example */#include <stdio.h>int main (){ char buffer [50]; int n, a=5, b=3; 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;}
Output:
[5 plus 3 is 8] is a string 13 chars long
0 0
- funciton sprintf
- read funciton
- funciton snprintf
- showdialog funciton
- funciton object & function pointer
- 激励函数-Activation Funciton
- sprintf
- sprintf
- sprintf
- sprintf
- sprintf
- sprintf()
- sprintf
- sprintf
- sprintf
- sprintf
- sprintf
- sprintf
- c++简单的习题
- Linux驱动之设备模型(8)
- 九度1538:GrassLand密码
- 思路整理随笔
- spring MVC原理
- funciton sprintf
- intellij idea常用的快捷键
- 装饰者模式
- sun的java编译器对string常量表达式的处理和优化
- 阿里共享业务事业部第二次电面
- NYOJ 116 士兵杀敌 二
- 二进制中1的个数
- dwr与weblogic报错问题
- dundas chart