1scanf(3)                   Library Functions Manual                   scanf(3)
2
3
4

NAME

6       scanf, fscanf, vscanf, vfscanf - input FILE format conversion
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <stdio.h>
13
14       int scanf(const char *restrict format, ...);
15       int fscanf(FILE *restrict stream,
16                  const char *restrict format, ...);
17
18       #include <stdarg.h>
19
20       int vscanf(const char *restrict format, va_list ap);
21       int vfscanf(FILE *restrict stream,
22                  const char *restrict format, va_list ap);
23
24   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
25
26       vscanf(), vfscanf():
27           _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
28

DESCRIPTION

30       The  scanf()  family  of functions scans input like sscanf(3), but read
31       from a FILE.  It is very difficult to use  these  functions  correctly,
32       and  it  is preferable to read entire lines with fgets(3) or getline(3)
33       and parse them later with sscanf(3) or more specialized functions  such
34       as strtol(3).
35
36       The  scanf()  function reads input from the standard input stream stdin
37       and fscanf() reads input from the stream pointer stream.
38
39       The vfscanf() function is analogous to vfprintf(3) and reads input from
40       the  stream  pointer  stream using a variable argument list of pointers
41       (see stdarg(3).  The vscanf() function is analogous to  vprintf(3)  and
42       reads from the standard input.
43

RETURN VALUE

45       On  success,  these functions return the number of input items success‐
46       fully matched and assigned; this can be fewer  than  provided  for,  or
47       even zero, in the event of an early matching failure.
48
49       The  value EOF is returned if the end of input is reached before either
50       the first successful conversion or a matching failure occurs.   EOF  is
51       also returned if a read error occurs, in which case the error indicator
52       for the stream (see ferror(3)) is set, and errno is set to indicate the
53       error.
54

ERRORS

56       EAGAIN The file descriptor underlying stream is marked nonblocking, and
57              the read operation would block.
58
59       EBADF  The file descriptor underlying stream is invalid,  or  not  open
60              for reading.
61
62       EILSEQ Input byte sequence does not form a valid character.
63
64       EINTR  The read operation was interrupted by a signal; see signal(7).
65
66       EINVAL Not enough arguments; or format is NULL.
67
68       ENOMEM Out of memory.
69

ATTRIBUTES

71       For  an  explanation  of  the  terms  used  in  this  section,  see at‐
72       tributes(7).
73
74       ┌─────────────────────────────────────┬───────────────┬────────────────┐
75Interface                            Attribute     Value          
76       ├─────────────────────────────────────┼───────────────┼────────────────┤
77scanf(), fscanf(), vscanf(),         │ Thread safety │ MT-Safe locale │
78vfscanf()                            │               │                │
79       └─────────────────────────────────────┴───────────────┴────────────────┘
80

STANDARDS

82       C11, POSIX.1-2008.
83

HISTORY

85       C99, POSIX.1-2001.
86

SEE ALSO

88       fgets(3), getline(3), sscanf(3)
89
90
91
92Linux man-pages 6.05              2023-07-20                          scanf(3)
Impressum