Skip to content

Instantly share code, notes, and snippets.

@Snigelson
Created January 6, 2014 14:13
Show Gist options
  • Save Snigelson/8283387 to your computer and use it in GitHub Desktop.
Save Snigelson/8283387 to your computer and use it in GitHub Desktop.
Dynamic vsprintf
/* Takes the same argumetns as vprintf. Allocates space to store the string and returns
* a pointer to it.
*/
static char* dynvsprintf(char* format, va_list argp)
{
char* buffer=NULL;
int length;
length = vsnprintf(NULL, 0, format, argp)+1;
buffer = malloc(length);
vsnprintf(buffer, length, format, argp);
return buffer;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment