my problem with vsprintf is that I can not obtain input arguments directly, I have to first get inputs one by one and save them in void**, then pas
If the problem you're trying to solve is inserting passing arbitrary types to a function in va_list style, then, consider using union:
#include
#include
union ARG
{
int d;
char* s;
double f;
};
int main()
{
printf("%d %s %f \n", 1, "two", 3.1415 );
// Output: 1 two 3.141500
char format[ 1024 ] = "%d %s %f\n";
ARG args[ 5 ] = { };
args[ 0 ].d = 1;
args[ 1 ].s = "two";
args[ 2 ].f = 3.1415;
printf( format, args[ 0 ], args[ 1 ], args[ 2 ], args[ 3 ], args[ 4 ] );
// Output: 1 two 3.141500
return 0;
}
Some things you'll note about my solution:
format and args.Tested this on: - Ubuntu, g++ - Android NDK
I did some more testing, and, confirmed @PeterCoordes comments about this answer not working for double precision.