Chinaunix首页 | 论坛 | 博客
  • 博客访问: 112487
  • 博文数量: 23
  • 博客积分: 975
  • 博客等级: 准尉
  • 技术积分: 262
  • 用 户 组: 普通用户
  • 注册时间: 2008-07-19 00:54
文章分类
文章存档

2011年(2)

2010年(3)

2008年(18)

我的朋友

分类: C/C++

2010-04-02 21:21:06

函数原型:
int asprintf(char **strp, const char *fmt, ...);



以下是man page的描述:
The functions asprintf() and vasprintf() are analogues of sprintf() and vsprintf(), except that they allocate a string large enough to hold the output including the terminating null byte, and return a pointer to it via the first parameter. This pointer should be passed to (3) to release the allocated storage when it is no longer needed.
asprintf()可以说是一个增强版的sprintf(),在不确定字符串的长度时,非常灵活方便,能够根据格式化的字符串长度,申请足够的内存空间。此外,使用完后,必须通过free()释放空间。

不过,这是GNU扩展的C函数库,不是标准C函数库或者POSIX。
阅读(3900) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~