fscanf, fwscanf

De RAD Studio
Aller à : navigation, rechercher

Remonter à Stdio.h - Index


Header File

stdio.h

Category

Input/output Routines

Prototype

int fscanf(FILE *stream, const char *format[, address, ...]);

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

Description

Scans and formats input from a stream.

fscanf scans a series of input fields one character at a time reading from a 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 format. The number of format specifiers and addresses must be the same as the number of input fields.

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

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

Return Value

fscanf returns the number of input fields successfully scanned, converted and stored. The return value does not include scanned fields that were not stored.

If fscanf attempts to read at end-of-file, the return value is EOF. If no fields were stored, the return value is 0.

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(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