snprintf() [and vsnprintf()] don't return the number of chars printed (as printf() do), but the number that would be printed. For example:
Code:
int size;
char buffer[10];
size = snprintf( buffer, sizeof buffer, "Frederico was here" );
// size will be 18, but buffer will be 9 chars + NUL char.
This is useful to dynamic allocate a buffer:
Code:
int size;
char *buffer, c;
size = snprintf( &c, 1, "%d", value ); // get the # of chars.
buffer = malloc( size + 1 );
snprintf( buffer, size + 1, "%d", value ); // again, but filling the allocated buffer.
PS: I don't know if it's prudent to use:
Code:
size = snprintf( NULL, 0, "%d", value );
So I prefer to use a single char.