vscanf_s, vwscanf_s

From RAD Studio
Jump to: navigation, search

Go Up to stdio.h Index

Header File



Formatted input/output functions


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

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


Replaces vscanf adding security enhancements.

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

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

vscanf_s scans a series of input fields, one character at a time, reading from stdin. Then each field is formatted according to a format specifier passed to vscanf in the format string pointed to by format. Finally, vscanf_s stores the formatted input at the addresses passed to it in the argument list. The number of format specifiers and addresses must be the same as the number of input fields.

vscanf_s might stop scanning a particular field before it reaches the normal end-of-field (whitespace) character, or it might terminate entirely, for a number of reasons. See scanf for a discussion of possible causes.

vscanf_s is equivalent to scanf_s, wscanf_s with the variable argument list replaced by arg. The vscanf_s function does not invoke the va_end macro.

Return Value

vscanf returns the number of input fields successfully scanned, converted, and stored; the return value does not include scanned fields that were not stored. If no fields were stored, the return value is zero.

If an error occurs, the return value is the value of the macro EOF.


#include <stdio.h>
#include <stdarg.h>
int vscnf(char *fmt, ...)
   va_list argptr;
   int cnt;
   printf("Enter an integer, a float, and a string (e.g. i,f,s,)\n");
   va_start(argptr, fmt);
   cnt = vscanf_s(fmt, argptr);
int main(void)
   int inumber;
   float fnumber;
   char string[80];
   vscnf("%d, %f, %s", &inumber, &fnumber, string);
   printf_s("%d %f %s\n", inumber, fnumber, string);
   return 0;






See Also