1 .\" @(#)scanf.3s 6.1 (Berkeley) 5/15/85
3 .TH SCANF 3 "May 15, 1985"
6 scanf, fscanf, sscanf, vscanf, vfscanf, vsscanf \- formatted input conversion
13 int scanf(const char *\fIformat\fP \fR[\fP, \fIpointer\fP\fR] ...\fP)
14 int fscanf(FILE *\fIstream\fP, const char *\fIformat\fP \fR[\fP, \fIpointer\fP\fR] ...\fP)
15 int sscanf(const char *\fIs\fP, const char *\fIformat\fP \fR[\fP, \fIpointer\fP\fR] ...\fP)
16 int vscanf(const char *\fIformat\fP, va_list \fIargs\fP)
17 int vfscanf(FILE *\fIstream\fP, const char *\fIformat\fP, va_list \fIargs\fP)
18 int vsscanf(const char *\fIs\fP, const char *\fIformat\fP, va_list \fIargs\fP)
21 reads from the standard input stream
24 reads from the named input
27 reads from the character string
29 Each function reads characters, interprets
30 them according to a format, and stores the results in its arguments.
31 Each expects as arguments
38 indicating where the converted input should be stored.
42 functions can be used to make functions like the first three by using the
44 method to process the argument pointers.
49 conversion specifications, which are used to direct interpretation
51 The control string may contain:
54 Blanks, tabs or newlines,
55 which match optional white space in the input.
58 An ordinary character (not %) which must match
59 the next character of the input stream.
62 Conversion specifications, consisting of the
65 an optional assignment suppressing character
67 an optional numerical maximum field width, and a conversion
70 A conversion specification directs the conversion of the
71 next input field; the result
72 is placed in the variable pointed to by the corresponding argument,
73 unless assignment suppression was
76 An input field is defined as a string of non-space characters;
77 it extends to the next inappropriate character or until the field
78 width, if specified, is exhausted.
80 The conversion character indicates the interpretation of the
81 input field; the corresponding pointer argument must
82 usually be of a restricted type.
83 The following conversion characters are legal:
86 a single `%' is expected
87 in the input at this point;
88 no assignment is done.
91 a decimal integer is expected;
92 the corresponding argument should be an integer pointer.
95 an octal integer is expected;
96 the corresponding argument should be a integer pointer.
99 a hexadecimal integer is expected;
100 the corresponding argument should be an integer pointer.
104 a character string is expected;
105 the corresponding argument should be a character pointer
106 pointing to an array of characters large enough to accept the
107 string and a terminating `\e0', which will be added.
108 The input field is terminated by a space character
112 a character is expected; the
113 corresponding argument should be a character pointer.
114 The normal skip over space characters is suppressed
116 to read the next non-space character, try
118 If a field width is given, the corresponding argument
119 should refer to a character array, and the
120 indicated number of characters is read.
123 a floating point number is expected;
124 the next field is converted accordingly and stored through the
125 corresponding argument, which should be a pointer to a
128 floating point numbers is
131 possibly containing a decimal point, followed by an optional
132 exponent field consisting of an E or e followed by an optionally signed integer.
135 indicates a string not to be delimited by space characters.
136 The left bracket is followed by a set of characters and a right
137 bracket; the characters between the brackets define a set
138 of characters making up the string.
139 If the first character
140 is not circumflex (\|^\|), the input field
141 is all characters until the first character not in the set between
142 the brackets; if the first character
143 after the left bracket is ^, the input field is all characters
144 until the first character which is in the remaining set of characters
145 between the brackets.
146 The corresponding argument must point to a character array.
148 The conversion characters
153 may be capitalized or preceded by
155 to indicate that a pointer to
159 is in the argument list.
160 Similarly, the conversion characters
165 may be capitalized or
168 to indicate a pointer to
172 The conversion characters
179 to indicate a pointer to
186 functions return the number of successfully matched and assigned input
188 This can be used to decide how many input items were found.
192 is returned upon end of input; note that this is different
193 from 0, which means that no conversion was done;
194 if conversion was intended, it was frustrated by an
195 inappropriate character in the input.
197 For example, the call
199 int i; float x; char name[50];
201 scanf("%d%f%s", &i, &x, name);
205 25 54.32E\(mi1 thompson
214 will contain `\fBthompson\e0\fP' .
217 int i; float x; char name[50];
219 scanf("%2d%f%*d%[1234567890]", &i, &x, name);
230 and place the string `56\e0' in
247 and a short count for missing or illegal data items.
249 The success of literal matches and suppressed
250 assignments is not directly