Last active
December 11, 2015 19:18
-
-
Save sgk/4647146 to your computer and use it in GitHub Desktop.
Compute the length printf would print.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdarg.h> | |
/* returns the length printf would print. */ | |
int | |
printflen(const char* format, ...) { | |
va_list ap; | |
char buf[1]; | |
int len; | |
va_start(ap, format); | |
len = vsnprintf(buf, sizeof (buf), format, ap); | |
va_end(ap); | |
return len; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment