vprintf_s, vwprintf_s

From RAD Studio
Jump to: navigation, search

Go Up to stdio.h Index


Header File

stdio.h

Category

Formatted input/output functions

Prototype

int vprintf_s(const char * restrict format, va_list arg);

int vwprintf_s(const wchar_t * restrict format, va_list arg);

Description

Replaces vprintf, vwprintf, adding security enhancements.

Note: Do not use this function in Win32 GUI applications.

The v...printf functions are known as alternate entry points for the ...printf functions. They behave exactly like their ...printf counterparts, but they accept a pointer to a list of arguments instead of an argument list.

vprintf_s is equivalent to vprintf, vwprintf, but it adds run-time constraints regarding the validity of stream, format, and the items in arg corresponding to a %s format specifier (all mentioned earlier must not be null pointers.)

Return Value

vprintf_s returns the number of characters output. In case of an error, vprintf_s returns a negative value.

Example

#include <stdio.h>
#include <stdarg.h>
int vpf(char *fmt, ...)
{
   va_list argptr;
   int cnt;
   va_start(argptr, fmt);
   cnt = vprintf_s(fmt, argptr);
   va_end(argptr);
   return(cnt);
}
int main(void)
{
   int inumber = 30;
   float fnumber = 90.0;
   char *string = "abc";
   vpf("%d %f %s\n",inumber,fnumber,string);
   return 0;
}

Portability

POSIX Win32 ANSI C ANSI C++

vprintf_s

+

+

+

+

vwprintf_s

+

+

+


See Also