scanf()
PROTOTYPE
#include <stdio.h>
int scanf(const char *format, ...);
DESCRIPTION
scanf() reads formatted input from the open regular file identified by stdin. format is interpreted according to Standard C’s input format string conventions. Any additional arguments are variable addresses 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, stdin’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 scanf() returns EOF. Otherwise, scanf() returns the number of assignments.
ERROR CODES
| EFAULT | format equals NULL. |
| EBADF | stdin is not the handle of a file open in read mode. |
| EISDIR | stdin refers to a directory. |
EXAMPLE
int i;
/*-----------------------------------------------------------------*/
/* Read an integer from stdin. */
/*-----------------------------------------------------------------*/
if (scanf("%d", &i) == EOF)
{
perror("error reading from file");
return -1;
}