fscanf_s, fwscanf_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 fscanf_s(FILE * restrict stream, const char * restrict format, [, address, ...]);

int fwscanf_s(FILE * restrict stream, const wchar_t * restrict format, [, address, ...]);

Description

Replaces fscanf, fwscanf adding security enhancements.

fscanf_s scans a series of input fields one character at a time reading from a dtream identified by stream. Then each field is formatted according to a format specifier passed to fscanf in the format string pointed to by format. Finally, fscanf stores the formatted input at an address passed to it as an argument following the format. The number of format specifiers and addresses must be the same as the number of input fields.

Note: For details on format specifiers, see scanf Format Specifiers.

Return Value

fscanf_s returns the number of input fields successfully scanned, converted, and stored. This value can be zero if the first field is a mismatch.

If an error occurs before any conversions, the return value is the macro EOF.

Example

#include <stdlib.h>
#include <stdio.h>
int main(void)
{
   int i;
   printf("Input an integer: ");
   /* Read an integer from the
      standard input stream */
   if (fscanf_s(stdin, "%d", &i))
      printf("The integer read was: %i\n", i);
   else
   {
      fprintf(stderr, "Error reading an integer from stdin.\n");
      exit(1);
   }
   return 0;
}

Portability

POSIX Win32 ANSI C ANSI C++

+

+

+

+

See Also