fork(1) download
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <stdarg.h>
  4.  
  5. void foo( const char format[], ... )
  6. {
  7. va_list args;
  8. size_t length = 0;
  9.  
  10. va_start( args, format );
  11.  
  12. length = vsnprintf( 0, 0, format, args );
  13.  
  14. ++length;
  15. char *pbuffer = new char[length];
  16.  
  17. vsprintf( pbuffer, format, args ); // тут пробовал и vsnprintf( pbuffer, length, format, args ) с тем же результатом
  18. printf( "%s", pbuffer );
  19.  
  20. va_end( args );
  21.  
  22. delete[] pbuffer;
  23. }
  24.  
  25. int main()
  26. {
  27. foo( "Hello %s World!\n", "cruel" );
  28.  
  29. return 0;
  30. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
Hello cruel World!