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