sprintf介绍

表头文件

#include<stdio.h>

定义函数

int sprintf( char *str,const char * format,.........);

函数说明

sprintf()会根据参数format字符串来转换并格式化数据,然后将结果复制到参数str所指的字符串数组,直到出现字符串结束(\0)为止。关于参数format字符串的格式请参考printf()

返回值

成功则返回参数str字符串长度,失败则返回-1,错误原因存于errno中。

附加说明

使用此函数得留意堆栈溢出,或改用snprintf()。

范例

#include<stdio.h>

main()

{

sprintf(s, "%8d%8d", 123, 4567); //产生:" 123 4567"

}

原文:

http://baike.baidu.com/view/1295144.htm

原文地址:https://www.cnblogs.com/mydomain/p/2770825.html