vprintf
Description:
Similar to the standard C `vsprintf()` function but safer, since it calculates the maximum space required and allocates memory to hold the result.
The returned string is guaranteed to be non-NULL, unless format
contains `lc` or `
ls` conversions, which can fail if no multibyte representation is available for the given character.
See also [func@GLib.vasprintf], which offers the same functionality, but additionally returns the length of the allocated string.
Example: Format a string with printf:
public static void my_printf (string format, ...) {
va_list va_list = va_list ();
string res = format.vprintf (va_list);
print (res);
}
public static int main (string[] args) {
// Output: ``Shut up, K-9!``
my_printf ("Shut %s, %c-%d!\n", "up", 'K', 9);
return 0;
}
valac --pkg glib-2.0 string.vprintf.vala
Parameters:
args |
the list of parameters to insert into the format string |
format |
a standard `printf()` format string, but notice [string precision pitfalls](string-utils.html#string-precision-pitfalls) |
Returns:
a newly-allocated string holding the result |