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