Programming Reference/Librarys
Question & Answer
Q&A is closed
int vsprintf(char *str, const char *format, va_list arg);
generate a string from a format string. For this purpose, the buffer that is passed as first argument, the format string is copied and replaces the substitution symbol with the given parameters.
/* * vsprintf example code * http://code-reference.com/c/stdio.h/vsprintf */ #include <stdio.h> /* including standard library */ //#include <windows.h> /* uncomment this for Windows */ #include <stdarg.h> int myprintf( char const * format, ... ) { va_list args; int n; char buffer[200]; va_start( args, format ); vsprintf( buffer, format, args ); va_end( args ); return printf("vsprintf example : %s", buffer); } int main (void) { char string[] ="Hello"; myprintf( " %s World\n", string); return 0; }
output: ./vsprintf vsprintf example : Hello World