C Tutorial/stdio.h/vprintf vfprintf vsprintf vsnprintf


Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179

Deprecated: Creation of dynamic property PPDStack::$accum is deprecated in /var/www/cppe.ru/www/includes/parser/Preprocessor_DOM.php on line 803

Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179

Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/vendor/mediawiki/at-ease/src/Functions.php on line 48
Материал из C\C++ эксперт
Перейти к: навигация, поиск

vprintf, vfprintf, vsprintf, and vsnprintf

Item Value Header file stdarg.h stdio.h Declaration int vprintf(char *format, va_list arg_ptr); int vfprintf(FILE *stream, const char *format, va_list arg_ptr); int vsprintf(char *buf, const char *format, va_list arg_ptr); int vsnprintf(char * restrict buf, size_t num, const char * restrict format, va_list arg_ptr);

The functions vprintf(), vfprintf(), vsprintf(), and vsnprintf() are functionally equivalent to printf(), fprintf(), sprintf(), and snprintf(), respectively , except that the argument list has been replaced by a pointer to a list of arguments.

This pointer must be of type va_list, which is defined in the header <stdarg.h>.


#include <stdio.h>
  #include <stdarg.h>
  void print_message(char *format, ...)
  {
    va_list ptr;
    va_start(ptr, format);
    vprintf(format, ptr);
    va_end(ptr);
  }
  int main(void)
  {
    print_message("Cannot open file %s.", "test");
    return 0;
  }