fscanf()
PROTOTYPE
#include <stdio.h>
int fscanf(FILE *file, const char *format, ...);
DESCRIPTION
fscanf() reads formatted input from the current position of the open regular file identified by file, advancing that position by the number of bytes read. format is interpreted according to Standard C’s input format string conventions. Any additional arguments are addresses of variables into which values are assigned.
Under control of the format string, bytes are read from the input stream, converted, and written to the provided variable addresses. Processing continues until a terminating null in the format string is reached, end-of-file is reached, or a conversion error occurs.
Unless disabled via FSF_NOATIME or only a byte pushed back by ungetc() is read, the file’s data access timestamp is updated.
If no input assignments are made before either end-of-file is reached or a conversion error occurs, errno is set and fscanf() returns EOF. Otherwise, fscanf() returns the number of assignments.
ERROR CODES
| EFAULT | format equals NULL. |
| EBADF | file is not the handle of a file open in read mode. |
| EISDIR | file refers to a directory. |
EXAMPLE
int i;
FILE *file;
/*-----------------------------------------------------------------*/
/* Open file for reading. */
/*-----------------------------------------------------------------*/
if ((file = fopen("/flash/meas.txt", "r")) == NULL)
return -1;
/*-----------------------------------------------------------------*/
/* Read an integer from stream. */
/*-----------------------------------------------------------------*/
if (fscanf(file, "%d", &i) == EOF)
return -1;