xref: /freebsd/lib/libc/stdio/scanf.3 (revision dc36d6f9bb1753f3808552f3afd30eda9a7b206a)
158f0484fSRodney W. Grimes.\" Copyright (c) 1990, 1991, 1993
258f0484fSRodney W. Grimes.\"	The Regents of the University of California.  All rights reserved.
358f0484fSRodney W. Grimes.\"
458f0484fSRodney W. Grimes.\" This code is derived from software contributed to Berkeley by
558f0484fSRodney W. Grimes.\" Chris Torek and the American National Standards Committee X3,
658f0484fSRodney W. Grimes.\" on Information Processing Systems.
758f0484fSRodney W. Grimes.\"
858f0484fSRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without
958f0484fSRodney W. Grimes.\" modification, are permitted provided that the following conditions
1058f0484fSRodney W. Grimes.\" are met:
1158f0484fSRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright
1258f0484fSRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer.
1358f0484fSRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright
1458f0484fSRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer in the
1558f0484fSRodney W. Grimes.\"    documentation and/or other materials provided with the distribution.
16fbbd9655SWarner Losh.\" 3. Neither the name of the University nor the names of its contributors
1758f0484fSRodney W. Grimes.\"    may be used to endorse or promote products derived from this software
1858f0484fSRodney W. Grimes.\"    without specific prior written permission.
1958f0484fSRodney W. Grimes.\"
2058f0484fSRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2158f0484fSRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2258f0484fSRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2358f0484fSRodney W. Grimes.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2458f0484fSRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2558f0484fSRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2658f0484fSRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2758f0484fSRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2858f0484fSRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2958f0484fSRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3058f0484fSRodney W. Grimes.\" SUCH DAMAGE.
3158f0484fSRodney W. Grimes.\"
32*bce0bef3SDag-Erling Smørgrav.Dd September 5, 2023
3358f0484fSRodney W. Grimes.Dt SCANF 3
3458f0484fSRodney W. Grimes.Os
3558f0484fSRodney W. Grimes.Sh NAME
3658f0484fSRodney W. Grimes.Nm scanf ,
3758f0484fSRodney W. Grimes.Nm fscanf ,
3858f0484fSRodney W. Grimes.Nm sscanf ,
3958f0484fSRodney W. Grimes.Nm vscanf ,
4058f0484fSRodney W. Grimes.Nm vsscanf ,
4158f0484fSRodney W. Grimes.Nm vfscanf
4258f0484fSRodney W. Grimes.Nd input format conversion
4325bb73e0SAlexey Zelkin.Sh LIBRARY
4425bb73e0SAlexey Zelkin.Lb libc
4558f0484fSRodney W. Grimes.Sh SYNOPSIS
4632eef9aeSRuslan Ermilov.In stdio.h
4758f0484fSRodney W. Grimes.Ft int
4854e4e385SMike Barcroft.Fn scanf "const char * restrict format" ...
4958f0484fSRodney W. Grimes.Ft int
5054e4e385SMike Barcroft.Fn fscanf "FILE * restrict stream" "const char * restrict format" ...
5158f0484fSRodney W. Grimes.Ft int
5254e4e385SMike Barcroft.Fn sscanf "const char * restrict str" "const char * restrict format" ...
5332eef9aeSRuslan Ermilov.In stdarg.h
5458f0484fSRodney W. Grimes.Ft int
5554e4e385SMike Barcroft.Fn vscanf "const char * restrict format" "va_list ap"
5658f0484fSRodney W. Grimes.Ft int
5754e4e385SMike Barcroft.Fn vsscanf "const char * restrict str" "const char * restrict format" "va_list ap"
5858f0484fSRodney W. Grimes.Ft int
5954e4e385SMike Barcroft.Fn vfscanf "FILE * restrict stream" "const char * restrict format" "va_list ap"
6058f0484fSRodney W. Grimes.Sh DESCRIPTION
6158f0484fSRodney W. GrimesThe
6258f0484fSRodney W. Grimes.Fn scanf
6358f0484fSRodney W. Grimesfamily of functions scans input according to a
6458f0484fSRodney W. Grimes.Fa format
6558f0484fSRodney W. Grimesas described below.
6658f0484fSRodney W. GrimesThis format may contain
6758f0484fSRodney W. Grimes.Em conversion specifiers ;
6858f0484fSRodney W. Grimesthe results from such conversions, if any,
6958f0484fSRodney W. Grimesare stored through the
7058f0484fSRodney W. Grimes.Em pointer
7158f0484fSRodney W. Grimesarguments.
7258f0484fSRodney W. GrimesThe
7358f0484fSRodney W. Grimes.Fn scanf
7458f0484fSRodney W. Grimesfunction
7558f0484fSRodney W. Grimesreads input from the standard input stream
76ae828962SRuslan Ermilov.Dv stdin ,
7758f0484fSRodney W. Grimes.Fn fscanf
7858f0484fSRodney W. Grimesreads input from the stream pointer
7958f0484fSRodney W. Grimes.Fa stream ,
8058f0484fSRodney W. Grimesand
8158f0484fSRodney W. Grimes.Fn sscanf
8258f0484fSRodney W. Grimesreads its input from the character string pointed to by
8358f0484fSRodney W. Grimes.Fa str .
8458f0484fSRodney W. GrimesThe
8558f0484fSRodney W. Grimes.Fn vfscanf
8658f0484fSRodney W. Grimesfunction
8758f0484fSRodney W. Grimesis analogous to
8858f0484fSRodney W. Grimes.Xr vfprintf 3
8958f0484fSRodney W. Grimesand reads input from the stream pointer
9058f0484fSRodney W. Grimes.Fa stream
9158f0484fSRodney W. Grimesusing a variable argument list of pointers (see
9258f0484fSRodney W. Grimes.Xr stdarg 3 ) .
9358f0484fSRodney W. GrimesThe
9458f0484fSRodney W. Grimes.Fn vscanf
9558f0484fSRodney W. Grimesfunction scans a variable argument list from the standard input and
9658f0484fSRodney W. Grimesthe
9758f0484fSRodney W. Grimes.Fn vsscanf
9858f0484fSRodney W. Grimesfunction scans it from a string;
9958f0484fSRodney W. Grimesthese are analogous to
10058f0484fSRodney W. Grimesthe
10158f0484fSRodney W. Grimes.Fn vprintf
10258f0484fSRodney W. Grimesand
10358f0484fSRodney W. Grimes.Fn vsprintf
10458f0484fSRodney W. Grimesfunctions respectively.
10558f0484fSRodney W. GrimesEach successive
10658f0484fSRodney W. Grimes.Em pointer
10758f0484fSRodney W. Grimesargument must correspond properly with
10858f0484fSRodney W. Grimeseach successive conversion specifier
10938261ac8SDima Dorfman(but see the
11038261ac8SDima Dorfman.Cm *
11138261ac8SDima Dorfmanconversion below).
11258f0484fSRodney W. GrimesAll conversions are introduced by the
11358f0484fSRodney W. Grimes.Cm %
11458f0484fSRodney W. Grimes(percent sign) character.
11558f0484fSRodney W. GrimesThe
11658f0484fSRodney W. Grimes.Fa format
11758f0484fSRodney W. Grimesstring
11858f0484fSRodney W. Grimesmay also contain other characters.
11958f0484fSRodney W. GrimesWhite space (such as blanks, tabs, or newlines) in the
12058f0484fSRodney W. Grimes.Fa format
12158f0484fSRodney W. Grimesstring match any amount of white space, including none, in the input.
12258f0484fSRodney W. GrimesEverything else
12358f0484fSRodney W. Grimesmatches only itself.
12458f0484fSRodney W. GrimesScanning stops
12558f0484fSRodney W. Grimeswhen an input character does not match such a format character.
12658f0484fSRodney W. GrimesScanning also stops
12758f0484fSRodney W. Grimeswhen an input conversion cannot be made (see below).
12858f0484fSRodney W. Grimes.Sh CONVERSIONS
12958f0484fSRodney W. GrimesFollowing the
13058f0484fSRodney W. Grimes.Cm %
13158f0484fSRodney W. Grimescharacter introducing a conversion
13258f0484fSRodney W. Grimesthere may be a number of
13358f0484fSRodney W. Grimes.Em flag
13458f0484fSRodney W. Grimescharacters, as follows:
135946b2d00SBill Fenner.Bl -tag -width ".Cm l No (ell)"
13658f0484fSRodney W. Grimes.It Cm *
13758f0484fSRodney W. GrimesSuppresses assignment.
13858f0484fSRodney W. GrimesThe conversion that follows occurs as usual, but no pointer is used;
13958f0484fSRodney W. Grimesthe result of the conversion is simply discarded.
140946b2d00SBill Fenner.It Cm hh
141946b2d00SBill FennerIndicates that the conversion will be one of
14276edfabbSDag-Erling Smørgrav.Cm bdioux
143946b2d00SBill Fenneror
144946b2d00SBill Fenner.Cm n
145946b2d00SBill Fennerand the next pointer is a pointer to a
146432e57ebSRuslan Ermilov.Vt char
147946b2d00SBill Fenner(rather than
148432e57ebSRuslan Ermilov.Vt int ) .
14958f0484fSRodney W. Grimes.It Cm h
15058f0484fSRodney W. GrimesIndicates that the conversion will be one of
15176edfabbSDag-Erling Smørgrav.Cm bdioux
15258f0484fSRodney W. Grimesor
15358f0484fSRodney W. Grimes.Cm n
15458f0484fSRodney W. Grimesand the next pointer is a pointer to a
155432e57ebSRuslan Ermilov.Vt "short int"
15658f0484fSRodney W. Grimes(rather than
157432e57ebSRuslan Ermilov.Vt int ) .
158946b2d00SBill Fenner.It Cm l No (ell)
159946b2d00SBill FennerIndicates that the conversion will be one of
16076edfabbSDag-Erling Smørgrav.Cm bdioux
16158f0484fSRodney W. Grimesor
16258f0484fSRodney W. Grimes.Cm n
16358f0484fSRodney W. Grimesand the next pointer is a pointer to a
164432e57ebSRuslan Ermilov.Vt "long int"
16558f0484fSRodney W. Grimes(rather than
166432e57ebSRuslan Ermilov.Vt int ) ,
167946b2d00SBill Fennerthat the conversion will be one of
168b6b7fb37SDavid Schultz.Cm a , e , f ,
169b6b7fb37SDavid Schultzor
170b6b7fb37SDavid Schultz.Cm g
17158f0484fSRodney W. Grimesand the next pointer is a pointer to
172432e57ebSRuslan Ermilov.Vt double
17358f0484fSRodney W. Grimes(rather than
174432e57ebSRuslan Ermilov.Vt float ) ,
175946b2d00SBill Fenneror that the conversion will be one of
1764712aa3bSTim J. Robbins.Cm c ,
177946b2d00SBill Fenner.Cm s
1784712aa3bSTim J. Robbinsor
1794712aa3bSTim J. Robbins.Cm \&[
180946b2d00SBill Fennerand the next pointer is a pointer to an array of
181432e57ebSRuslan Ermilov.Vt wchar_t
182946b2d00SBill Fenner(rather than
183432e57ebSRuslan Ermilov.Vt char ) .
184946b2d00SBill Fenner.It Cm ll No (ell ell)
185946b2d00SBill FennerIndicates that the conversion will be one of
18676edfabbSDag-Erling Smørgrav.Cm bdioux
1875e17038fSJordan K. Hubbardor
1885e17038fSJordan K. Hubbard.Cm n
1895e17038fSJordan K. Hubbardand the next pointer is a pointer to a
190432e57ebSRuslan Ermilov.Vt "long long int"
1915e17038fSJordan K. Hubbard(rather than
192432e57ebSRuslan Ermilov.Vt int ) .
193946b2d00SBill Fenner.It Cm L
194946b2d00SBill FennerIndicates that the conversion will be one of
195b6b7fb37SDavid Schultz.Cm a , e , f ,
196946b2d00SBill Fenneror
197946b2d00SBill Fenner.Cm g
198946b2d00SBill Fennerand the next pointer is a pointer to
199432e57ebSRuslan Ermilov.Vt "long double" .
200946b2d00SBill Fenner.It Cm j
201946b2d00SBill FennerIndicates that the conversion will be one of
20276edfabbSDag-Erling Smørgrav.Cm bdioux
203946b2d00SBill Fenneror
204946b2d00SBill Fenner.Cm n
205946b2d00SBill Fennerand the next pointer is a pointer to a
206432e57ebSRuslan Ermilov.Vt intmax_t
207946b2d00SBill Fenner(rather than
208432e57ebSRuslan Ermilov.Vt int ) .
209946b2d00SBill Fenner.It Cm t
210946b2d00SBill FennerIndicates that the conversion will be one of
21176edfabbSDag-Erling Smørgrav.Cm bdioux
212946b2d00SBill Fenneror
213946b2d00SBill Fenner.Cm n
214946b2d00SBill Fennerand the next pointer is a pointer to a
215432e57ebSRuslan Ermilov.Vt ptrdiff_t
216946b2d00SBill Fenner(rather than
217432e57ebSRuslan Ermilov.Vt int ) .
218*bce0bef3SDag-Erling Smørgrav.It Cm w Ns Ar N
219*bce0bef3SDag-Erling Smørgrav.Po
220*bce0bef3SDag-Erling Smørgravwhere
221*bce0bef3SDag-Erling Smørgrav.Ar N
222*bce0bef3SDag-Erling Smørgravis 8, 16, 32, or 64
223*bce0bef3SDag-Erling Smørgrav.Pc
224*bce0bef3SDag-Erling SmørgravIndicates that the conversion will be one of
225*bce0bef3SDag-Erling Smørgrav.Cm bdioux
226*bce0bef3SDag-Erling Smørgravor
227*bce0bef3SDag-Erling Smørgrav.Cm n
228*bce0bef3SDag-Erling Smørgravand the next pointer is a pointer to a
229*bce0bef3SDag-Erling Smørgrav.Vt intN_t
230*bce0bef3SDag-Erling Smørgrav(rather than
231*bce0bef3SDag-Erling Smørgrav.Vt int ) .
232*bce0bef3SDag-Erling Smørgrav.It Cm wf Ns Ar N
233*bce0bef3SDag-Erling Smørgrav.Po
234*bce0bef3SDag-Erling Smørgravwhere
235*bce0bef3SDag-Erling Smørgrav.Ar N
236*bce0bef3SDag-Erling Smørgravis 8, 16, 32, or 64
237*bce0bef3SDag-Erling Smørgrav.Pc
238*bce0bef3SDag-Erling SmørgravIndicates that the conversion will be one of
239*bce0bef3SDag-Erling Smørgrav.Cm bdioux
240*bce0bef3SDag-Erling Smørgravor
241*bce0bef3SDag-Erling Smørgrav.Cm n
242*bce0bef3SDag-Erling Smørgravand the next pointer is a pointer to a
243*bce0bef3SDag-Erling Smørgrav.Vt int_fastN_t
244*bce0bef3SDag-Erling Smørgrav(rather than
245*bce0bef3SDag-Erling Smørgrav.Vt int ) .
246946b2d00SBill Fenner.It Cm z
247946b2d00SBill FennerIndicates that the conversion will be one of
24876edfabbSDag-Erling Smørgrav.Cm bdioux
249946b2d00SBill Fenneror
250946b2d00SBill Fenner.Cm n
251946b2d00SBill Fennerand the next pointer is a pointer to a
252432e57ebSRuslan Ermilov.Vt size_t
253946b2d00SBill Fenner(rather than
254432e57ebSRuslan Ermilov.Vt int ) .
255946b2d00SBill Fenner.It Cm q
256946b2d00SBill Fenner(deprecated.)
257946b2d00SBill FennerIndicates that the conversion will be one of
25876edfabbSDag-Erling Smørgrav.Cm bdioux
259946b2d00SBill Fenneror
260946b2d00SBill Fenner.Cm n
261946b2d00SBill Fennerand the next pointer is a pointer to a
262432e57ebSRuslan Ermilov.Vt "long long int"
263946b2d00SBill Fenner(rather than
264432e57ebSRuslan Ermilov.Vt int ) .
26558f0484fSRodney W. Grimes.El
26658f0484fSRodney W. Grimes.Pp
26758f0484fSRodney W. GrimesIn addition to these flags,
26858f0484fSRodney W. Grimesthere may be an optional maximum field width,
26958f0484fSRodney W. Grimesexpressed as a decimal integer,
27058f0484fSRodney W. Grimesbetween the
27158f0484fSRodney W. Grimes.Cm %
27258f0484fSRodney W. Grimesand the conversion.
27358f0484fSRodney W. GrimesIf no width is given,
274432e57ebSRuslan Ermilova default of
275432e57ebSRuslan Ermilov.Dq infinity
276432e57ebSRuslan Ermilovis used (with one exception, below);
2774712aa3bSTim J. Robbinsotherwise at most this many bytes are scanned
27858f0484fSRodney W. Grimesin processing the conversion.
2794712aa3bSTim J. RobbinsIn the case of the
2804712aa3bSTim J. Robbins.Cm lc ,
2814712aa3bSTim J. Robbins.Cm ls
2824712aa3bSTim J. Robbinsand
2834712aa3bSTim J. Robbins.Cm l[
2844712aa3bSTim J. Robbinsconversions, the field width specifies the maximum number
2854712aa3bSTim J. Robbinsof multibyte characters that will be scanned.
28658f0484fSRodney W. GrimesBefore conversion begins,
28758f0484fSRodney W. Grimesmost conversions skip white space;
28858f0484fSRodney W. Grimesthis white space is not counted against the field width.
28958f0484fSRodney W. Grimes.Pp
29058f0484fSRodney W. GrimesThe following conversions are available:
29158f0484fSRodney W. Grimes.Bl -tag -width XXXX
29258f0484fSRodney W. Grimes.It Cm %
293432e57ebSRuslan ErmilovMatches a literal
294432e57ebSRuslan Ermilov.Ql % .
295432e57ebSRuslan ErmilovThat is,
296432e57ebSRuslan Ermilov.Dq Li %%
297432e57ebSRuslan Ermilovin the format string
298432e57ebSRuslan Ermilovmatches a single input
299432e57ebSRuslan Ermilov.Ql %
300432e57ebSRuslan Ermilovcharacter.
30158f0484fSRodney W. GrimesNo conversion is done, and assignment does not occur.
30276edfabbSDag-Erling Smørgrav.It Cm b , B
30376edfabbSDag-Erling SmørgravMatches an optionally signed binary integer;
30476edfabbSDag-Erling Smørgravthe next pointer must be a pointer to
30576edfabbSDag-Erling Smørgrav.Vt "unsigned int" .
30658f0484fSRodney W. Grimes.It Cm d
30758f0484fSRodney W. GrimesMatches an optionally signed decimal integer;
30858f0484fSRodney W. Grimesthe next pointer must be a pointer to
309432e57ebSRuslan Ermilov.Vt int .
31058f0484fSRodney W. Grimes.It Cm i
31158f0484fSRodney W. GrimesMatches an optionally signed integer;
31258f0484fSRodney W. Grimesthe next pointer must be a pointer to
313432e57ebSRuslan Ermilov.Vt int .
31476edfabbSDag-Erling SmørgravThe integer is read
31576edfabbSDag-Erling Smørgravin base 2 if it begins with
31676edfabbSDag-Erling Smørgrav.Ql 0b
31776edfabbSDag-Erling Smørgravor
31876edfabbSDag-Erling Smørgrav.Ql 0B ,
31976edfabbSDag-Erling Smørgravin base 16 if it begins
32058f0484fSRodney W. Grimeswith
32158f0484fSRodney W. Grimes.Ql 0x
32258f0484fSRodney W. Grimesor
32358f0484fSRodney W. Grimes.Ql 0X ,
32458f0484fSRodney W. Grimesin base 8 if it begins with
32558f0484fSRodney W. Grimes.Ql 0 ,
32658f0484fSRodney W. Grimesand in base 10 otherwise.
32758f0484fSRodney W. GrimesOnly characters that correspond to the base are used.
32858f0484fSRodney W. Grimes.It Cm o
32958f0484fSRodney W. GrimesMatches an octal integer;
33058f0484fSRodney W. Grimesthe next pointer must be a pointer to
331432e57ebSRuslan Ermilov.Vt "unsigned int" .
33258f0484fSRodney W. Grimes.It Cm u
33358f0484fSRodney W. GrimesMatches an optionally signed decimal integer;
33458f0484fSRodney W. Grimesthe next pointer must be a pointer to
335432e57ebSRuslan Ermilov.Vt "unsigned int" .
336946b2d00SBill Fenner.It Cm x , X
33758f0484fSRodney W. GrimesMatches an optionally signed hexadecimal integer;
33858f0484fSRodney W. Grimesthe next pointer must be a pointer to
339432e57ebSRuslan Ermilov.Vt "unsigned int" .
340b6b7fb37SDavid Schultz.It Cm a , A , e , E , f , F , g , G
341b6b7fb37SDavid SchultzMatches a floating-point number in the style of
342b6b7fb37SDavid Schultz.Xr strtod 3 .
343b6b7fb37SDavid SchultzThe next pointer must be a pointer to
344b6b7fb37SDavid Schultz.Vt float
345b6b7fb37SDavid Schultz(unless
346b6b7fb37SDavid Schultz.Cm l
347b6b7fb37SDavid Schultzor
348b6b7fb37SDavid Schultz.Cm L
349b6b7fb37SDavid Schultzis specified.)
35058f0484fSRodney W. Grimes.It Cm s
35158f0484fSRodney W. GrimesMatches a sequence of non-white-space characters;
35258f0484fSRodney W. Grimesthe next pointer must be a pointer to
353432e57ebSRuslan Ermilov.Vt char ,
35458f0484fSRodney W. Grimesand the array must be large enough to accept all the sequence and the
35558f0484fSRodney W. Grimesterminating
35658f0484fSRodney W. Grimes.Dv NUL
35758f0484fSRodney W. Grimescharacter.
35858f0484fSRodney W. GrimesThe input string stops at white space
35958f0484fSRodney W. Grimesor at the maximum field width, whichever occurs first.
3604712aa3bSTim J. Robbins.Pp
3614712aa3bSTim J. RobbinsIf an
3624712aa3bSTim J. Robbins.Cm l
3634712aa3bSTim J. Robbinsqualifier is present, the next pointer must be a pointer to
3644712aa3bSTim J. Robbins.Vt wchar_t ,
3654712aa3bSTim J. Robbinsinto which the input will be placed after conversion by
3664712aa3bSTim J. Robbins.Xr mbrtowc 3 .
367946b2d00SBill Fenner.It Cm S
368946b2d00SBill FennerThe same as
369946b2d00SBill Fenner.Cm ls .
37058f0484fSRodney W. Grimes.It Cm c
37158f0484fSRodney W. GrimesMatches a sequence of
37258f0484fSRodney W. Grimes.Em width
37358f0484fSRodney W. Grimescount
37458f0484fSRodney W. Grimescharacters (default 1);
37558f0484fSRodney W. Grimesthe next pointer must be a pointer to
376432e57ebSRuslan Ermilov.Vt char ,
37758f0484fSRodney W. Grimesand there must be enough room for all the characters
37858f0484fSRodney W. Grimes(no terminating
37958f0484fSRodney W. Grimes.Dv NUL
38058f0484fSRodney W. Grimesis added).
38158f0484fSRodney W. GrimesThe usual skip of leading white space is suppressed.
38258f0484fSRodney W. GrimesTo skip white space first, use an explicit space in the format.
3834712aa3bSTim J. Robbins.Pp
3844712aa3bSTim J. RobbinsIf an
3854712aa3bSTim J. Robbins.Cm l
3864712aa3bSTim J. Robbinsqualifier is present, the next pointer must be a pointer to
3874712aa3bSTim J. Robbins.Vt wchar_t ,
3884712aa3bSTim J. Robbinsinto which the input will be placed after conversion by
3894712aa3bSTim J. Robbins.Xr mbrtowc 3 .
390946b2d00SBill Fenner.It Cm C
391946b2d00SBill FennerThe same as
392946b2d00SBill Fenner.Cm lc .
39358f0484fSRodney W. Grimes.It Cm \&[
39458f0484fSRodney W. GrimesMatches a nonempty sequence of characters from the specified set
39558f0484fSRodney W. Grimesof accepted characters;
39658f0484fSRodney W. Grimesthe next pointer must be a pointer to
397432e57ebSRuslan Ermilov.Vt char ,
39858f0484fSRodney W. Grimesand there must be enough room for all the characters in the string,
39958f0484fSRodney W. Grimesplus a terminating
40058f0484fSRodney W. Grimes.Dv NUL
40158f0484fSRodney W. Grimescharacter.
40258f0484fSRodney W. GrimesThe usual skip of leading white space is suppressed.
40358f0484fSRodney W. GrimesThe string is to be made up of characters in
40458f0484fSRodney W. Grimes(or not in)
40558f0484fSRodney W. Grimesa particular set;
40658f0484fSRodney W. Grimesthe set is defined by the characters between the open bracket
407790752beSJoel Dahl.Cm \&[
40858f0484fSRodney W. Grimescharacter
40958f0484fSRodney W. Grimesand a close bracket
410790752beSJoel Dahl.Cm \&]
41158f0484fSRodney W. Grimescharacter.
41258f0484fSRodney W. GrimesThe set
41358f0484fSRodney W. Grimes.Em excludes
41458f0484fSRodney W. Grimesthose characters
41558f0484fSRodney W. Grimesif the first character after the open bracket is a circumflex
41658f0484fSRodney W. Grimes.Cm ^ .
41758f0484fSRodney W. GrimesTo include a close bracket in the set,
41858f0484fSRodney W. Grimesmake it the first character after the open bracket
41958f0484fSRodney W. Grimesor the circumflex;
42058f0484fSRodney W. Grimesany other position will end the set.
42158f0484fSRodney W. GrimesThe hyphen character
42258f0484fSRodney W. Grimes.Cm -
42358f0484fSRodney W. Grimesis also special;
42458f0484fSRodney W. Grimeswhen placed between two other characters,
42558f0484fSRodney W. Grimesit adds all intervening characters to the set.
42658f0484fSRodney W. GrimesTo include a hyphen,
42758f0484fSRodney W. Grimesmake it the last character before the final close bracket.
42858f0484fSRodney W. GrimesFor instance,
42958f0484fSRodney W. Grimes.Ql [^]0-9-]
430432e57ebSRuslan Ermilovmeans the set
431432e57ebSRuslan Ermilov.Dq "everything except close bracket, zero through nine, and hyphen" .
43258f0484fSRodney W. GrimesThe string ends with the appearance of a character not in the
43358f0484fSRodney W. Grimes(or, with a circumflex, in) set
43458f0484fSRodney W. Grimesor when the field width runs out.
4354712aa3bSTim J. Robbins.Pp
4364712aa3bSTim J. RobbinsIf an
4374712aa3bSTim J. Robbins.Cm l
4384712aa3bSTim J. Robbinsqualifier is present, the next pointer must be a pointer to
4394712aa3bSTim J. Robbins.Vt wchar_t ,
4404712aa3bSTim J. Robbinsinto which the input will be placed after conversion by
4414712aa3bSTim J. Robbins.Xr mbrtowc 3 .
44258f0484fSRodney W. Grimes.It Cm p
44358f0484fSRodney W. GrimesMatches a pointer value (as printed by
44458f0484fSRodney W. Grimes.Ql %p
44558f0484fSRodney W. Grimesin
44658f0484fSRodney W. Grimes.Xr printf 3 ) ;
44758f0484fSRodney W. Grimesthe next pointer must be a pointer to
448432e57ebSRuslan Ermilov.Vt void .
44958f0484fSRodney W. Grimes.It Cm n
45058f0484fSRodney W. GrimesNothing is expected;
45158f0484fSRodney W. Grimesinstead, the number of characters consumed thus far from the input
45258f0484fSRodney W. Grimesis stored through the next pointer,
45358f0484fSRodney W. Grimeswhich must be a pointer to
454432e57ebSRuslan Ermilov.Vt int .
45558f0484fSRodney W. GrimesThis is
45658f0484fSRodney W. Grimes.Em not
45758f0484fSRodney W. Grimesa conversion, although it can be suppressed with the
45858f0484fSRodney W. Grimes.Cm *
45958f0484fSRodney W. Grimesflag.
46058f0484fSRodney W. Grimes.El
46158f0484fSRodney W. Grimes.Pp
46236db5680SAndrey A. ChernovThe decimal point
463429d919cSRuslan Ermilovcharacter is defined in the program's locale (category
464429d919cSRuslan Ermilov.Dv LC_NUMERIC ) .
46536db5680SAndrey A. Chernov.Pp
466432e57ebSRuslan ErmilovFor backwards compatibility, a
467432e57ebSRuslan Ermilov.Dq conversion
468432e57ebSRuslan Ermilovof
46958f0484fSRodney W. Grimes.Ql %\e0
47058f0484fSRodney W. Grimescauses an immediate return of
47158f0484fSRodney W. Grimes.Dv EOF .
47258f0484fSRodney W. Grimes.Sh RETURN VALUES
47358f0484fSRodney W. GrimesThese
47458f0484fSRodney W. Grimesfunctions
47558f0484fSRodney W. Grimesreturn
47658f0484fSRodney W. Grimesthe number of input items assigned, which can be fewer than provided
47758f0484fSRodney W. Grimesfor, or even zero, in the event of a matching failure.
47858f0484fSRodney W. GrimesZero
47958f0484fSRodney W. Grimesindicates that, while there was input available,
48058f0484fSRodney W. Grimesno conversions were assigned;
48158f0484fSRodney W. Grimestypically this is due to an invalid input character,
48258f0484fSRodney W. Grimessuch as an alphabetic character for a
48358f0484fSRodney W. Grimes.Ql %d
48458f0484fSRodney W. Grimesconversion.
48558f0484fSRodney W. GrimesThe value
48658f0484fSRodney W. Grimes.Dv EOF
48758f0484fSRodney W. Grimesis returned if an input failure occurs before any conversion such as an
488c6ff3a1bSSheldon Hearnend-of-file occurs.
489c6ff3a1bSSheldon HearnIf an error or end-of-file occurs after conversion
49058f0484fSRodney W. Grimeshas begun,
49158f0484fSRodney W. Grimesthe number of conversions which were successfully completed is returned.
49258f0484fSRodney W. Grimes.Sh SEE ALSO
49358f0484fSRodney W. Grimes.Xr getc 3 ,
49438b5abadSTim J. Robbins.Xr mbrtowc 3 ,
49575141cc9SWolfram Schneider.Xr printf 3 ,
49675141cc9SWolfram Schneider.Xr strtod 3 ,
49775141cc9SWolfram Schneider.Xr strtol 3 ,
49838b5abadSTim J. Robbins.Xr strtoul 3 ,
49938b5abadSTim J. Robbins.Xr wscanf 3
50058f0484fSRodney W. Grimes.Sh STANDARDS
50158f0484fSRodney W. GrimesThe functions
50258f0484fSRodney W. Grimes.Fn fscanf ,
50358f0484fSRodney W. Grimes.Fn scanf ,
5045a7405beSTim J. Robbins.Fn sscanf ,
5055a7405beSTim J. Robbins.Fn vfscanf ,
5065a7405beSTim J. Robbins.Fn vscanf
50758f0484fSRodney W. Grimesand
5085a7405beSTim J. Robbins.Fn vsscanf
50958f0484fSRodney W. Grimesconform to
510946b2d00SBill Fenner.St -isoC-99 .
5114b7f35dbSGordon Bergling.Sh HISTORY
5124b7f35dbSGordon BerglingThe functions
5134b7f35dbSGordon Bergling.Fn scanf ,
5144b7f35dbSGordon Bergling.Fn fscanf ,
5154b7f35dbSGordon Berglingand
5164b7f35dbSGordon Bergling.Fn sscanf
5174b7f35dbSGordon Berglingfirst appeared in
5184b7f35dbSGordon Bergling.At v7 ,
5194b7f35dbSGordon Berglingand
5204b7f35dbSGordon Bergling.Fn vscanf ,
5214b7f35dbSGordon Bergling.Fn vsscanf ,
5224b7f35dbSGordon Berglingand
5234b7f35dbSGordon Bergling.Fn vfscanf
5244b7f35dbSGordon Berglingin
5254b7f35dbSGordon Bergling.Bx 4.3 Reno .
52658f0484fSRodney W. Grimes.Sh BUGS
527946b2d00SBill FennerEarlier implementations of
528946b2d00SBill Fenner.Nm
529946b2d00SBill Fennertreated
530946b2d00SBill Fenner.Cm \&%D , \&%E , \&%F , \&%O
53158f0484fSRodney W. Grimesand
532946b2d00SBill Fenner.Cm \&%X
533946b2d00SBill Fenneras their lowercase equivalents with an
534946b2d00SBill Fenner.Cm l
535432e57ebSRuslan Ermilovmodifier.
536432e57ebSRuslan ErmilovIn addition,
537946b2d00SBill Fenner.Nm
538946b2d00SBill Fennertreated an unknown conversion character as
539946b2d00SBill Fenner.Cm \&%d
540946b2d00SBill Fenneror
541946b2d00SBill Fenner.Cm \&%D ,
542432e57ebSRuslan Ermilovdepending on its case.
543432e57ebSRuslan ErmilovThis functionality has been removed.
54458f0484fSRodney W. Grimes.Pp
54558f0484fSRodney W. GrimesNumerical strings are truncated to 512 characters; for example,
54658f0484fSRodney W. Grimes.Cm %f
54758f0484fSRodney W. Grimesand
54858f0484fSRodney W. Grimes.Cm %d
54958f0484fSRodney W. Grimesare implicitly
55058f0484fSRodney W. Grimes.Cm %512f
55158f0484fSRodney W. Grimesand
55258f0484fSRodney W. Grimes.Cm %512d .
553946b2d00SBill Fenner.Pp
554946b2d00SBill FennerThe
555946b2d00SBill Fenner.Cm %n$
556946b2d00SBill Fennermodifiers for positional arguments are not implemented.
557946b2d00SBill Fenner.Pp
558946b2d00SBill FennerThe
559e2b090f3STim J. Robbins.Nm
560e2b090f3STim J. Robbinsfamily of functions do not correctly handle multibyte characters in the
561e2b090f3STim J. Robbins.Fa format
562e2b090f3STim J. Robbinsargument.
563