1 .\" Copyright (c) 1990, 1991, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" This code is derived from software contributed to Berkeley by
5 .\" Chris Torek and the American National Standards Committee X3,
6 .\" on Information Processing Systems.
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\" notice, this list of conditions and the following disclaimer.
13 .\" 2. Redistributions in binary form must reproduce the above copyright
14 .\" notice, this list of conditions and the following disclaimer in the
15 .\" documentation and/or other materials provided with the distribution.
16 .\" 3. All advertising materials mentioning features or use of this software
17 .\" must display the following acknowledgement:
18 .\" This product includes software developed by the University of
19 .\" California, Berkeley and its contributors.
20 .\" 4. Neither the name of the University nor the names of its contributors
21 .\" may be used to endorse or promote products derived from this software
22 .\" without specific prior written permission.
24 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 .\" @(#)scanf.3 8.2 (Berkeley) 12/11/93
37 .\" $FreeBSD: src/lib/libc/stdio/scanf.3,v 1.24 2003/06/28 09:03:25 das Exp $
49 .Nd input format conversion
56 .Fa "FILE *restrict stream"
57 .Fa "const char *restrict format" ...
61 .Fa "const char *restrict format" ...
65 .Fa "const char *restrict s"
66 .Fa "const char *restrict format" ...
72 .Fa "FILE *restrict stream"
73 .Fa "const char *restrict format"
78 .Fa "const char *restrict format"
83 .Fa "const char *restrict s"
84 .Fa "const char *restrict format"
90 family of functions scans input according to a
93 This format may contain
94 .Em conversion specifiers ;
95 the results from such conversions, if any,
96 are stored through the
102 reads input from the standard input stream
105 reads input from the stream pointer
109 reads its input from the character string pointed to by
117 and reads input from the stream pointer
119 using a variable argument list of pointers (see
123 function scans a variable argument list from the standard input and
126 function scans it from a string;
127 these are analogous to
132 functions, respectively.
136 argument must correspond properly with
137 each successive conversion specifier
141 All conversions are introduced by the
143 (percent sign) character.
147 may also contain other characters.
148 White space (such as blanks, tabs, or newlines) in the
150 string match any amount of white space, including none, in the input.
154 when an input character does not match such a format character.
156 when an input conversion cannot be made (see below).
158 Extended locale versions of these functions are documented in
162 for more information.
166 character introducing a conversion,
167 there may be a number of
169 characters, as follows:
170 .Bl -tag -width ".Cm l No (ell)"
172 Suppresses assignment.
173 The conversion that follows occurs as usual, but no pointer is used;
174 the result of the conversion is simply discarded.
176 Indicates that the conversion will be one of
180 and the next pointer is a pointer to a
185 Indicates that the conversion will be one of
189 and the next pointer is a pointer to a
194 Indicates that the conversion will be one of
198 and the next pointer is a pointer to a
202 that the conversion will be one of
206 and the next pointer is a pointer to
210 or that the conversion will be one of
215 and the next pointer is a pointer to an array of
219 .It Cm ll No (ell ell)
220 Indicates that the conversion will be one of
224 and the next pointer is a pointer to a
229 Indicates that the conversion will be one of
233 and the next pointer is a pointer to
236 Indicates that the conversion will be one of
240 and the next pointer is a pointer to a
245 Indicates that the conversion will be one of
249 and the next pointer is a pointer to a
254 Indicates that the conversion will be one of
258 and the next pointer is a pointer to a
264 Indicates that the conversion will be one of
268 and the next pointer is a pointer to a
274 In addition to these flags,
275 there may be an optional maximum field width,
276 expressed as a decimal integer,
280 If no width is given,
283 is used (with one exception, below);
284 otherwise at most this many bytes are scanned
285 in processing the conversion.
291 conversions, the field width specifies the maximum number
292 of multibyte characters that will be scanned.
293 Before conversion begins,
294 most conversions skip white space;
295 this white space is not counted against the field width.
297 The following conversions are available:
305 matches a single input
308 No conversion is done, and assignment does not occur.
310 Matches an optionally signed decimal integer;
311 the next pointer must be a pointer to
314 Matches an optionally signed integer;
315 the next pointer must be a pointer to
317 The integer is read in base 16 if it begins
322 in base 8 if it begins with
324 and in base 10 otherwise.
325 Only characters that correspond to the base are used.
327 Matches an octal integer;
328 the next pointer must be a pointer to
331 Matches an optionally signed decimal integer;
332 the next pointer must be a pointer to
335 Matches an optionally signed hexadecimal integer;
336 the next pointer must be a pointer to
338 .It Cm a , A , e , E , f , F , g , G
339 Matches a floating-point number in the style of
341 The next pointer must be a pointer to
349 Matches a sequence of non-white-space characters;
350 the next pointer must be a pointer to
352 and the array must be large enough to accept all the sequence and the
356 The input string stops at white space
357 or at the maximum field width, whichever occurs first.
361 qualifier is present, the next pointer must be a pointer to
363 into which the input will be placed after conversion by
369 Matches a sequence of
372 characters (default 1);
373 the next pointer must be a pointer to
375 and there must be enough room for all the characters
379 The usual skip of leading white space is suppressed.
380 To skip white space first, use an explicit space in the format.
384 qualifier is present, the next pointer must be a pointer to
386 into which the input will be placed after conversion by
392 Matches a nonempty sequence of characters from the specified set
393 of accepted characters;
394 the next pointer must be a pointer to
396 and there must be enough room for all the characters in the string,
400 The usual skip of leading white space is suppressed.
401 The string is to be made up of characters in
404 the set is defined by the characters between the open bracket
413 if the first character after the open bracket is a circumflex
415 To include a close bracket in the set,
416 make it the first character after the open bracket
418 any other position will end the set.
422 when placed between two other characters,
423 it adds all intervening characters to the set.
425 make it the last character before the final close bracket.
429 .Dq "everything except close bracket, zero through nine, and hyphen" .
430 The string ends with the appearance of a character not in the
431 (or, with a circumflex, in) set
432 or when the field width runs out.
436 qualifier is present, the next pointer must be a pointer to
438 into which the input will be placed after conversion by
441 Matches a pointer value (as printed by
445 the next pointer must be a pointer to
449 instead, the number of characters consumed thus far from the input
450 is stored through the next pointer,
451 which must be a pointer to
455 a conversion, although it can be suppressed with the
461 character is defined in the program's locale (category
464 For backwards compatibility, a
468 causes an immediate return of
471 These functions return the number of input items assigned.
472 This can be fewer than provided for, or even zero,
473 in the event of a matching failure.
474 Zero indicates that, although there was input available,
475 no conversions were assigned;
476 typically this is due to an invalid input character,
477 such as an alphabetic character for a
482 is returned if an input failure occurs before any conversion such as an
484 If an error or end-of-file occurs after conversion
486 the number of conversions which were successfully completed is returned.
508 Earlier implementations of
511 .Cm \&%D , \&%E , \&%F , \&%O
514 as their lowercase equivalents with an
519 treated an unknown conversion character as
523 depending on its case.
524 This functionality has been removed.
526 Numerical strings are truncated to 512 characters; for example,
537 modifiers for positional arguments are not implemented.
541 family of functions do not correctly handle multibyte characters in the