1SCANF(3S)                                                            SCANF(3S)
2
3
4

NAME

6       scanf, fscanf, sscanf - formatted input conversion
7

SYNOPSIS

9       #include <stdio.h>
10
11       scanf(format [ , pointer ] . . .  )
12       char *format;
13
14       fscanf(stream, format [ , pointer ] . . .  )
15       FILE *stream;
16       char *format;
17
18       sscanf(s, format [ , pointer ] . . .  )
19       char *s, *format;
20

DESCRIPTION

22       Scanf  reads  from  the standard input stream stdin.  Fscanf reads from
23       the named input stream.  Sscanf reads  from  the  character  string  s.
24       Each  function reads characters, interprets them according to a format,
25       and stores the results in its arguments.  Each expects as  arguments  a
26       control  string format, described below, and a set of pointer arguments
27       indicating where the converted input should be stored.
28
29       The control string usually contains  conversion  specifications,  which
30       are  used  to  direct  interpretation  of input sequences.  The control
31       string may contain:
32
33       1.  Blanks, tabs or newlines, which match optional white space  in  the
34           input.
35
36       2.  An  ordinary  character (not %) which must match the next character
37           of the input stream.
38
39       3.  Conversion  specifications,  consisting  of  the  character  %,  an
40           optional  assignment suppressing character *, an optional numerical
41           maximum field width, and a conversion character.
42
43       A conversion specification directs the conversion  of  the  next  input
44       field;  the  result  is placed in the variable pointed to by the corre‐
45       sponding argument, unless assignment suppression was  indicated  by  *.
46       An  input  field  is  defined  as  a string of non-space characters; it
47       extends to the next inappropriate character or until the  field  width,
48       if specified, is exhausted.
49
50       The  conversion  character  indicates  the  interpretation of the input
51       field;  the  corresponding  pointer  argument  must  usually  be  of  a
52       restricted type.  The following conversion characters are legal:
53
54       %   a  single `%' is expected in the input at this point; no assignment
55           is done.
56
57       d   a decimal integer is expected; the corresponding argument should be
58           an integer pointer.
59
60       o   an  octal integer is expected; the corresponding argument should be
61           a integer pointer.
62
63       x   a hexadecimal  integer  is  expected;  the  corresponding  argument
64           should be an integer pointer.
65
66       s   a  character  string is expected; the corresponding argument should
67           be a character pointer pointing to an  array  of  characters  large
68           enough  to  accept the string and a terminating `\0', which will be
69           added.  The input field is terminated by a  space  character  or  a
70           newline.
71
72       c   a  character  is  expected;  the corresponding argument should be a
73           character pointer.  The normal skip over space characters  is  sup‐
74           pressed  in  this  case;  to read the next non-space character, try
75           `%1s'.  If a field  width  is  given,  the  corresponding  argument
76           should  refer  to  a  character  array, and the indicated number of
77           characters is read.
78
79       e   a floating point number is expected; the next  field  is  converted
80       f   accordingly  and  stored  through the corresponding argument, which
81           should be a pointer to a float.   The  input  format  for