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

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

Description

Replaces vfscanf adding security enhancements.

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.

vfscanf_s is equivalent to vfscanf, 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

vfscanf_s 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 0.

If vfscanf_s encounters an input error, the return value is EOF.

Example

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
FILE *fp;
int vfsf(char *fmt, ...)
{
   va_list  argptr;
   int cnt;
   va_start(argptr, fmt);
   cnt = vfscanf_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);
   }
   fprintf(fp,"%d %f %s\n",inumber,fnumber,string);
   rewind(fp);
   vfsf("%d %f %s",&inumber,&fnumber,string);
   printf("%d %f %s\n",inumber,fnumber,string);
   fclose(fp);
   return 0;
}

Portability

POSIX Win32 ANSI C ANSI C++

+

+

+

See Also