g_strdup_printf是glibc下的函数
g_strdup_printf是一个和sprintf差不多的函数,但是 g_strdup_printf更安全和智能,并且在释放的时候也只能用 g_free (至于为什么更安全,我也想知道,有知道的请留言告诉我) . g_strdup_printf为分析一段buffer(也不理解)
例子:
#include <stdio.h>
#include <glib.h>
int main() {
char *a = "aaaaaaaaaaa";
char *t = g_strdup_printf ("%s", a);
printf("%s", t);
}
g_strdup_printf ()
gchar * g_strdup_printf (const gchar *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 g_free()
when no longer needed.
Parameters
format | a standard | |
... | the parameters to insert into the format string |
Returns
a newly-allocated string holding the result