]> git.saurik.com Git - apple/libc.git/blame - stdio/wscanf.3
Libc-498.tar.gz
[apple/libc.git] / stdio / wscanf.3
CommitLineData
224c7076
A
1.\" Copyright (c) 1990, 1991, 1993
2.\" The Regents of the University of California. All rights reserved.
3.\"
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.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
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.
23.\"
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
34.\" SUCH DAMAGE.
35.\"
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
38.\" $FreeBSD: src/lib/libc/stdio/wscanf.3,v 1.6 2003/07/05 07:47:55 tjr Exp $
39.\"
40.Dd July 5, 2003
41.Dt WSCANF 3
42.Os
43.Sh NAME
44.Nm fwscanf ,
45.Nm swscanf ,
46.Nm vfwscanf ,
47.Nm vswscanf ,
48.Nm vwscanf ,
49.Nm wscanf
50.Nd wide character input format conversion
51.Sh LIBRARY
52.Lb libc
53.Sh SYNOPSIS
54.In stdio.h
55.In wchar.h
56.Ft int
57.Fo fwscanf
58.Fa "FILE *restrict stream"
59.Fa "const wchar_t *restrict format"
60.Fa ...
61.Fc
62.Ft int
63.Fo swscanf
64.Fa "const wchar_t *restrict ws"
65.Fa "const wchar_t *restrict format"
66.Fa ...
67.Fc
68.Ft int
69.Fo wscanf
70.Fa "const wchar_t *restrict format"
71.Fa ...
72.Fc
73.In stdarg.h
74.In stdio.h
75.In wchar.h
76.Ft int
77.Fo vfwscanf
78.Fa "FILE *restrict stream"
79.Fa "const wchar_t *restrict format"
80.Fa "va_list arg"
81.Fc
82.Ft int
83.Fo vswscanf
84.Fa "const wchar_t *restrict ws"
85.Fa "const wchar_t *restrict format"
86.Fa "va_list arg"
87.Fc
88.Ft int
89.Fo vwscanf
90.Fa "const wchar_t *restrict format"
91.Fa "va_list arg"
92.Fc
93.Sh DESCRIPTION
94The
95.Fn wscanf
96family of functions scans input, according to a
97.Fa format
98as described below.
99This format may contain
100.Em conversion specifiers ;
101the results from such conversions, if any,
102are stored through the
103.Em pointer
104arguments.
105The
106.Fn wscanf
107function
108reads input from the standard input stream
109.Dv stdin ,
110.Fn fwscanf
111reads input from the stream pointer
112.Fa stream ,
113and
114.Fn swscanf
115reads its input from the wide character string pointed to by
116.Fa ws .
117.Pp
118The
119.Fn vfwscanf
120function
121is analogous to
122.Xr vfwprintf 3
123and reads input from the stream pointer
124.Fa stream
125using a variable argument list of pointers (see
126.Xr stdarg 3 ) .
127The
128.Fn vwscanf
129function scans a variable argument list from the standard input and
130the
131.Fn vswscanf
132function scans it from a wide character string;
133these are analogous to
134the
135.Fn vwprintf
136and
137.Fn vswprintf
138functions respectively.
139Each successive
140.Em pointer
141argument must correspond properly with
142each successive conversion specifier
143(but see the
144.Cm *
145conversion below).
146All conversions are introduced by the
147.Cm %
148(percent sign) character.
149.Pp
150The
151.Fa format
152string
153may also contain other characters.
154White space (such as blanks, tabs, or newlines) in the
155.Fa format
156string match any amount of white space, including none, in the input.
157Everything else
158matches only itself.
159Scanning stops
160when an input character does not match such a format character.
161Scanning also stops
162when an input conversion cannot be made (see below).
163.Pp
164Extended locale versions of these functions are documented in
165.Xr wscanf_l 3 .
166See
167.Xr xlocale 3
168for more information.
169.Sh CONVERSIONS
170Following the
171.Cm %
172character introducing a conversion,
173there may be a number of
174.Em flag
175characters, as follows:
176.Bl -tag -width ".Cm l No (ell)"
177.It Cm *
178Suppresses assignment.
179The conversion that follows occurs as usual, but no pointer is used;
180the result of the conversion is simply discarded.
181.It Cm hh
182Indicates that the conversion will be one of
183.Cm dioux
184or
185.Cm n
186and the next pointer is a pointer to a
187.Vt char
188(rather than
189.Vt int ) .
190.It Cm h
191Indicates that the conversion will be one of
192.Cm dioux
193or
194.Cm n
195and the next pointer is a pointer to a
196.Vt "short int"
197(rather than
198.Vt int ) .
199.It Cm l No (ell)
200Indicates that the conversion will be one of
201.Cm dioux
202or
203.Cm n
204and the next pointer is a pointer to a
205.Vt "long int"
206(rather than
207.Vt int ) ,
208that the conversion will be one of
209.Cm a , e , f ,
210or
211.Cm g
212and the next pointer is a pointer to
213.Vt double
214(rather than
215.Vt float ) ,
216or that the conversion will be one of
217.Cm c
218or
219.Cm s
220and the next pointer is a pointer to an array of
221.Vt wchar_t
222(rather than
223.Vt char ) .
224.It Cm ll No (ell ell)
225Indicates that the conversion will be one of
226.Cm dioux
227or
228.Cm n
229and the next pointer is a pointer to a
230.Vt "long long int"
231(rather than
232.Vt int ) .
233.It Cm L
234Indicates that the conversion will be one of
235.Cm a , e , f ,
236or
237.Cm g
238and the next pointer is a pointer to
239.Vt "long double" .
240.It Cm j
241Indicates that the conversion will be one of
242.Cm dioux
243or
244.Cm n
245and the next pointer is a pointer to a
246.Vt intmax_t
247(rather than
248.Vt int ) .
249.It Cm t
250Indicates that the conversion will be one of
251.Cm dioux
252or
253.Cm n
254and the next pointer is a pointer to a
255.Vt ptrdiff_t
256(rather than
257.Vt int ) .
258.It Cm z
259Indicates that the conversion will be one of
260.Cm dioux
261or
262.Cm n
263and the next pointer is a pointer to a
264.Vt size_t
265(rather than
266.Vt int ) .
267.It Cm q
268(deprecated.)
269Indicates that the conversion will be one of
270.Cm dioux
271or
272.Cm n
273and the next pointer is a pointer to a
274.Vt "long long int"
275(rather than
276.Vt int ) .
277.El
278.Pp
279In addition to these flags,
280there may be an optional maximum field width,
281expressed as a decimal integer,
282between the
283.Cm %
284and the conversion.
285If no width is given,
286a default of
287.Dq infinity
288is used (with one exception, below);
289otherwise at most this many characters are scanned
290in processing the conversion.
291Before conversion begins,
292most conversions skip white space;
293this white space is not counted against the field width.
294.Pp
295The following conversions are available:
296.Bl -tag -width XXXX
297.It Cm %
298Matches a literal
299.Ql % .
300That is,
301.Dq Li %%
302in the format string
303matches a single input
304.Ql %
305character.
306No conversion is done, and assignment does not occur.
307.It Cm d
308Matches an optionally signed decimal integer;
309the next pointer must be a pointer to
310.Vt int .
311.It Cm i
312Matches an optionally signed integer;
313the next pointer must be a pointer to
314.Vt int .
315The integer is read in base 16 if it begins
316with
317.Ql 0x
318or
319.Ql 0X ,
320in base 8 if it begins with
321.Ql 0 ,
322and in base 10 otherwise.
323Only characters that correspond to the base are used.
324.It Cm o
325Matches an octal integer;
326the next pointer must be a pointer to
327.Vt "unsigned int" .
328.It Cm u
329Matches an optionally signed decimal integer;
330the next pointer must be a pointer to
331.Vt "unsigned int" .
332.It Cm x , X
333Matches an optionally signed hexadecimal integer;
334the next pointer must be a pointer to
335.Vt "unsigned int" .
336.It Cm a , A , e , E , f , F , g , G
337Matches a floating-point number in the style of
338.Xr wcstod 3 .
339The next pointer must be a pointer to
340.Vt float
341(unless
342.Cm l
343or
344.Cm L
345is specified.)
346.It Cm s
347Matches a sequence of non-white-space wide characters;
348the next pointer must be a pointer to
349.Vt char ,
350and the array must be large enough to accept the multibyte representation
351of all the sequence and the
352terminating
353.Dv NUL
354character.
355The input string stops at white space
356or at the maximum field width, whichever occurs first.
357.Pp
358If an
359.Cm l
360qualifier is present, the next pointer must be a pointer to
361.Vt wchar_t ,
362into which the input will be placed.
363.It Cm S
364The same as
365.Cm ls .
366.It Cm c
367Matches a sequence of
368.Em width
369count
370wide characters (default 1);
371the next pointer must be a pointer to
372.Vt char ,
373and there must be enough room for the multibyte representation
374of all the characters
375(no terminating
376.Dv NUL
377is added).
378The usual skip of leading white space is suppressed.
379To skip white space first, use an explicit space in the format.
380.Pp
381If an
382.Cm l
383qualifier is present, the next pointer must be a pointer to
384.Vt wchar_t ,
385into which the input will be placed.
386.It Cm C
387The same as
388.Cm lc .
389.It Cm \&[
390Matches a nonempty sequence of characters from the specified set
391of accepted characters;
392the next pointer must be a pointer to
393.Vt char ,
394and there must be enough room for the multibyte representation of
395all the characters in the string,
396plus a terminating
397.Dv NUL
398character.
399The usual skip of leading white space is suppressed.
400The string is to be made up of characters in
401(or not in)
402a particular set;
403the set is defined by the characters between the open bracket
404.Cm [
405character
406and a close bracket
407.Cm ]
408character.
409The set
410.Em excludes
411those characters
412if the first character after the open bracket is a circumflex
413.Cm ^ .
414To include a close bracket in the set,
415make it the first character after the open bracket
416or the circumflex;
417any other position will end the set.
418To include a hyphen in the set,
419make it the last character before the final close bracket;
420some implementations of
421.Fn wscanf
422use
423.Dq Li A-Z
424to represent the range of characters between
425.Ql A
426and
427.Ql Z .
428The string ends with the appearance of a character not in the
429(or, with a circumflex, in) set
430or when the field width runs out.
431.Pp
432If an
433.Cm l
434qualifier is present, the next pointer must be a pointer to
435.Vt wchar_t ,
436into which the input will be placed.
437.It Cm p
438Matches a pointer value (as printed by
439.Ql %p
440in
441.Xr wprintf 3 ) ;
442the next pointer must be a pointer to
443.Vt void .
444.It Cm n
445Nothing is expected;
446instead, the number of characters consumed thus far from the input
447is stored through the next pointer,
448which must be a pointer to
449.Vt int .
450This is
451.Em not
452a conversion, although it can be suppressed with the
453.Cm *
454flag.
455.El
456.Pp
457The decimal point
458character is defined in the program's locale (category
459.Dv LC_NUMERIC ) .
460.Pp
461For backwards compatibility, a
462.Dq conversion
463of
464.Ql %\e0
465causes an immediate return of
466.Dv EOF .
467.Sh RETURN VALUES
468These functions return the number of input items assigned,
469which can be fewer than provided for, or even zero,
470in the event of a matching failure.
471Zero indicates that, while there was input available,
472no conversions were assigned;
473typically, this is due to an invalid input character,
474such as an alphabetic character for a
475.Ql %d
476conversion.
477The value
478.Dv EOF
479is returned if an input failure occurs before any conversion such as an
480end-of-file occurs.
481If an error or end-of-file occurs after conversion
482has begun,
483the number of conversions which were successfully completed is returned.
484.Sh SEE ALSO
485.Xr fgetwc 3 ,
486.Xr scanf 3 ,
487.Xr wcrtomb 3 ,
488.Xr wcstod 3 ,
489.Xr wcstol 3 ,
490.Xr wcstoul 3 ,
491.Xr wprintf 3 ,
492.Xr wscanf_l 3
493.Sh STANDARDS
494The
495.Fn fwscanf ,
496.Fn wscanf ,
497.Fn swscanf ,
498.Fn vfwscanf ,
499.Fn vwscanf ,
500and
501.Fn vswscanf
502functions
503conform to
504.St -isoC-99 .
505.Sh BUGS
506In addition to the bugs documented in
507.Xr scanf 3 ,
508.Fn wscanf
509does not support the
510.Dq Li A-Z
511notation for specifying character ranges with the character
512class conversion
513.Pq Sq Cm %[ .