g_strdup_printf
发布日期:2021-09-16 04:36:59 浏览次数:6 分类:技术文章

本文共 768 字,大约阅读时间需要 2 分钟。

g_strdup_printf是glibc下的函数

g_strdup_printf是一个和sprintf差不多的函数,但是 g_strdup_printf更安全和智能,并且在释放的时候也只能用 g_free (至于为什么更安全,我也想知道,有知道的请留言告诉我)  .  g_strdup_printf为分析一段buffer(也不理解)

例子:

#include 
#include
int main() { char *a = "aaaaaaaaaaa"; char *t = g_strdup_printf ("%s", a); printf("%s", t);}

g_strdup_printf ()

 *g_strdup_printf (const  *format,                 ...);

Similar to the standard C sprintf() function but safer, since it calculates the maximum space required and allocates memory to hold the result. The returned string should be freed with  when no longer needed.

Parameters

format

a standard printf() format string, but notice 

 

...

the parameters to insert into the format string

 

Returns

a newly-allocated string holding the result



转载地址:https://blog.csdn.net/wllabs/article/details/77850972 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:openstack irc chat log
下一篇:virsh 查看cpu架构,以及guest vm numa应分配架构

发表评论

最新留言

不错!
[***.144.177.141]2024年04月17日 07时12分37秒