vfprintf_s, vfwprintf_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 vfprintf_s(FILE * restrict stream, const char * restrict format, va_list arg);

int vfwprintf_s(FILE * restrict stream, const wchar_t * restrict format, va_list arg);

Description

Replaces vfprintf, vfwprintf adding security enhancements.

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

vfprintf_s is equivalent to vfprintf, vfwprintf, 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).

vfprintf_s accepts a pointer to a series of arguments, applies a format specifier contained in the format string pointed to by format to each argument, and outputs the formatted data to a stream. The number of format specifiers in the argument list (arg) must be the same as the number of items.

Return Value

On success, vfprintf returns the number of characters output.

On error, it returns a negative value.

Example

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
FILE *fp;
int vfpf(char *fmt, ...)
{
   va_list argptr;
   int cnt;
   va_start(argptr, fmt);
   cnt = vfprintf_s(fp, fmt, argptr);
   va_end(argptr);
   return(cnt);
}
int main(void)
{
   int inumber = 30;
   float fnumber = 90.0;
   char string[4] = "abc";
   fp = tmpfile();
   if (fp == NULL)
   {
      perror("tmpfile() call");
      exit(1);
   }
   vfpf("%d %f %s", inumber, fnumber, string);
   rewind(fp);
   fscanf_s(fp,"%d %f %s", &inumber, &fnumber, string);
   printf_s("%d %f %s\n", inumber, fnumber, string);
   fclose(fp);
   return 0;
}

Portability

POSIX Win32 ANSI C ANSI C++

vfprintf_s

+

+

+

+

vfwprintf_s

+

+

+

See Also