1.\" $OpenBSD: wscanf.3,v 1.5 2019/08/30 20:27:25 jmc Exp $ 2.\" 3.\" Copyright (c) 1990, 1991, 1993 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" This code is derived from software contributed to Berkeley by 7.\" Chris Torek and the American National Standards Committee X3, 8.\" on Information Processing Systems. 9.\" 10.\" Redistribution and use in source and binary forms, with or without 11.\" modification, are permitted provided that the following conditions 12.\" are met: 13.\" 1. Redistributions of source code must retain the above copyright 14.\" notice, this list of conditions and the following disclaimer. 15.\" 2. Redistributions in binary form must reproduce the above copyright 16.\" notice, this list of conditions and the following disclaimer in the 17.\" documentation and/or other materials provided with the distribution. 18.\" 3. Neither the name of the University nor the names of its contributors 19.\" may be used to endorse or promote products derived from this software 20.\" without specific prior written permission. 21.\" 22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32.\" SUCH DAMAGE. 33.\" 34.\" @(#)scanf.3 8.2 (Berkeley) 12/11/93 35.\" FreeBSD: src/lib/libc/stdio/scanf.3,v 1.24 2003/06/28 09:03:25 das Exp 36.\" 37.Dd $Mdocdate: August 30 2019 $ 38.Dt WSCANF 3 39.Os 40.Sh NAME 41.Nm wscanf , 42.Nm fwscanf , 43.Nm swscanf , 44.Nm vwscanf , 45.Nm vswscanf , 46.Nm vfwscanf 47.Nd wide character input format conversion 48.Sh SYNOPSIS 49.In stdio.h 50.In wchar.h 51.Ft int 52.Fn wscanf "const wchar_t * restrict format" ... 53.Ft int 54.Fn fwscanf "FILE * restrict stream" "const wchar_t * restrict format" ... 55.Ft int 56.Fn swscanf "const wchar_t * restrict str" "const wchar_t * restrict format" ... 57.In stdarg.h 58.Ft int 59.Fn vwscanf "const wchar_t * restrict format" "va_list ap" 60.Ft int 61.Fn vswscanf "const wchar_t * restrict str" "const wchar_t * restrict format" "va_list ap" 62.Ft int 63.Fn vfwscanf "FILE * restrict stream" "const wchar_t * restrict format" "va_list ap" 64.Sh DESCRIPTION 65The 66.Fn wscanf 67family of functions read input according to the given 68.Fa format 69as described below. 70This format may contain 71.Dq conversion specifiers ; 72the results of such conversions, if any, are stored through a set of pointer 73arguments. 74.Pp 75The 76.Fn wscanf 77function reads input from the standard input stream 78.Em stdin , 79.Fn fwscanf 80reads input from the supplied stream pointer 81.Fa stream , 82and 83.Fn swscanf 84reads its input from the wide character string pointed to by 85.Fa str . 86.Pp 87The 88.Fn vfwscanf 89function is analogous to 90.Xr vfwprintf 3 91and reads input from the stream pointer 92.Fa stream 93using a variable argument list of pointers (see 94.Xr va_start 3 ) . 95The 96.Fn vwscanf 97function scans a variable argument list from the standard input and the 98.Fn vswscanf 99function scans it from a wide character string; these are analogous to the 100.Fn vwprintf 101and 102.Fn vswprintf 103functions, respectively. 104.Pp 105Each successive 106.Em pointer 107argument must correspond properly with each successive conversion specifier 108(but see the 109.Cm * 110conversion below). 111All conversions are introduced by the 112.Cm % 113(percent sign) character. 114The 115.Fa format 116string may also contain other characters. 117Whitespace (such as blanks, tabs, or newlines) in the 118.Fa format 119string match any amount of whitespace, including none, in the input. 120Everything else matches only itself. 121Scanning stops when an input character does not match such a format character. 122Scanning also stops when an input conversion cannot be made (see below). 123.Sh CONVERSIONS 124Following the 125.Cm % 126character, introducing a conversion, there may be a number of 127.Em flag 128characters, as follows: 129.Bl -tag -width "ll (ell ell)" 130.It Cm * 131Suppresses assignment. 132The conversion that follows occurs as usual, but no pointer is used; 133the result of the conversion is simply discarded. 134.It Cm hh 135Indicates that the conversion will be one of 136.Cm dioux 137or 138.Cm n 139and the next pointer is a pointer to a 140.Vt char 141(rather than 142.Vt int ) . 143.It Cm h 144Indicates that the conversion will be one of 145.Cm dioux 146or 147.Cm n 148and the next pointer is a pointer to a 149.Vt "short int" 150(rather than 151.Vt int ) . 152.It Cm l No (ell) 153Indicates that the conversion will be one of 154.Cm dioux 155or 156.Cm n 157and the next pointer is a pointer to a 158.Vt "long int" 159(rather than 160.Vt int ) , 161that the conversion will be one of 162.Cm aefg 163and the next pointer is a pointer to 164.Vt double 165(rather than 166.Vt float ) , 167or that the conversion will be one of 168.Cm c 169or 170.Cm s 171and the next pointer is a pointer to an array of 172.Vt wchar_t 173(rather than 174.Vt char ) . 175.It Cm ll No (ell ell) 176Indicates that the conversion will be one of 177.Cm dioux 178or 179.Cm n 180and the next pointer is a pointer to a 181.Vt "long long int" 182(rather than 183.Vt int ) . 184.It Cm L 185Indicates that the conversion will be one of 186.Cm aefg 187and the next pointer is a pointer to 188.Vt "long double" . 189.It Cm j 190Indicates that the conversion will be one of 191.Cm dioux 192or 193.Cm n 194and the next pointer is a pointer to an 195.Vt intmax_t 196(rather than 197.Vt int ) . 198.It Cm t 199Indicates that the conversion will be one of 200.Cm dioux 201or 202.Cm n 203and the next pointer is a pointer to a 204.Vt ptrdiff_t 205(rather than 206.Vt int ) . 207.It Cm z 208Indicates that the conversion will be one of 209.Cm dioux 210or 211.Cm n 212and the next pointer is a pointer to a 213.Vt size_t 214(rather than 215.Vt int ) . 216.It Cm q 217(deprecated) 218Indicates that the conversion will be one of 219.Cm dioux 220or 221.Cm n 222and the next pointer is a pointer to a 223.Vt "long long int" 224(rather than 225.Vt int ) . 226.El 227.Pp 228In addition to these flags, there may be an optional maximum field width, 229expressed as a decimal integer, between the 230.Cm % 231and the conversion. 232If no width is given, 233a default of 234.Dq infinity 235is used (with one exception, below); 236otherwise at most this many characters are scanned in processing the 237conversion. 238Before conversion begins, most conversions skip whitespace; 239this whitespace is not counted against the field width. 240.Pp 241The following conversions are available: 242.Bl -tag -width XXXX 243.It Cm % 244Matches a literal 245.Ql % . 246That is, 247.Dq Li %% 248in the format string matches a single input 249.Ql % 250character. 251No conversion is done, and assignment does not occur. 252.It Cm d 253Matches an optionally signed decimal integer; 254the next pointer must be a pointer to 255.Vt int . 256.It Cm i 257Matches an optionally signed integer; 258the next pointer must be a pointer to 259.Vt int . 260The integer is read in base 16 if it begins 261with 262.Ql 0x 263or 264.Ql 0X , 265in base 8 if it begins with 266.Ql 0 , 267and in base 10 otherwise. 268Only characters that correspond to the base are used. 269.It Cm o 270Matches an octal integer; 271the next pointer must be a pointer to 272.Vt "unsigned int" . 273.It Cm u 274Matches an optionally signed decimal integer; 275the next pointer must be a pointer to 276.Vt "unsigned int" . 277.It Cm xX 278Matches an optionally signed hexadecimal integer; 279the next pointer must be a pointer to 280.Vt "unsigned int" . 281.It Cm a , A , e , E , f , F , g , G 282Matches a floating-point number in the style of 283.Xr wcstod 3 . 284The next pointer must be a pointer to 285.Vt float 286(unless 287.Cm l 288or 289.Cm L 290is specified.) 291.It Cm s 292Matches a sequence of non-whitespace wide characters; 293the next pointer must be a pointer to 294.Vt char , 295and the provided array must be large enough to accept and store 296the multibyte representation of the whole sequence and the 297terminating NUL character. 298The input string stops at whitespace 299or at the maximum field width, whichever occurs first. 300If specified, the maximum field length refers to the sequence 301being scanned rather than the storage space, hence the provided 302array must be 1 larger for the terminating NUL character. 303.Pp 304If an 305.Cm l 306qualifier is present, the next pointer must be a pointer to 307.Vt wchar_t , 308into which the input will be placed. 309.It Cm c 310Matches a sequence of wide characters consuming the number of wide characters 311specified by the field width (defaults to 1 if unspecified); 312the next pointer must be a pointer to 313.Vt char , 314and there must be enough room for the multibyte representation 315of all the characters 316(no terminating NUL is added). 317The usual skip of leading whitespace is suppressed. 318To skip whitespace first, use an explicit space in the format. 319.Pp 320If an 321.Cm l 322qualifier is present, the next pointer must be a pointer to 323.Vt wchar_t , 324into which the input will be placed. 325.It Cm \&[ 326Matches a nonempty sequence of characters from the specified set 327of accepted characters; 328the next pointer must be a pointer to 329.Vt char , 330and there must be enough room for the multibyte representation of 331all the characters in the string, 332plus a terminating NUL character. 333The usual skip of leading whitespace is suppressed. 334.Pp 335The string is to be made up of characters in 336(or not in) 337a particular set; 338the set is defined by the characters between the open bracket 339.Cm \&[ 340character 341and a close bracket 342.Cm \&] 343character. 344The set 345.Em excludes 346those characters 347if the first character after the open bracket is a circumflex 348.Cm ^ . 349To include a close bracket in the set, 350make it the first character after the open bracket 351or the circumflex; 352any other position will end the set. 353To include a hyphen in the set, 354make it the last character before the final close bracket; 355some implementations of 356.Fn wscanf 357use 358.Dq Li A-Z 359to represent the range of characters between 360.Ql A 361and 362.Ql Z . 363The string ends with the appearance of a character not in 364(or, with a circumflex, in) the set 365or when the field width runs out. 366.Pp 367If an 368.Cm l 369qualifier is present, the next pointer must be a pointer to 370.Vt wchar_t , 371into which the input will be placed. 372.It Cm p 373Matches a pointer value (as printed by 374.Ql %p 375in 376.Xr wprintf 3 ) ; 377the next pointer must be a pointer to 378.Vt void . 379.It Cm n 380Nothing is expected; 381instead, the number of characters consumed thus far from the input 382is stored through the next pointer, 383which must be a pointer to 384.Vt int . 385This is 386.Em not 387a conversion, although it can be suppressed with the 388.Cm * 389flag. 390.El 391.Pp 392For backwards compatibility, a 393.Dq conversion 394of 395.Ql %\e0 396causes an immediate return of 397.Dv EOF . 398.Sh RETURN VALUES 399These functions return the number of input items assigned, which can be fewer 400than provided for, or even zero, in the event of a matching failure. 401Zero indicates that, while there was input available, no conversions were 402assigned; typically this is due to an invalid input character, 403such as an alphabetic character for a 404.Ql %d 405conversion. 406The value 407.Dv EOF 408is returned if an input failure occurs before any conversion such as an 409end-of-file occurs. 410If an error or end-of-file occurs after conversion has begun, 411the number of conversions which were successfully completed is returned. 412.Sh SEE ALSO 413.Xr fgetwc 3 , 414.Xr scanf 3 , 415.Xr wcrtomb 3 , 416.Xr wcstod 3 , 417.Xr wcstol 3 , 418.Xr wcstoul 3 , 419.Xr wprintf 3 420.Sh STANDARDS 421The functions 422.Fn wscanf , 423.Fn fwscanf , 424.Fn swscanf , 425.Fn vwscanf , 426.Fn vfwscanf , 427and 428.Fn vswscanf 429conform to 430.St -isoC-99 . 431.Sh CAVEATS 432On systems other than 433.Ox , 434the 435.Dv LC_NUMERIC 436.Xr locale 1 437category can cause parsing failures; see CAVEATS in 438.Xr setlocale 3 439for details. 440.Sh BUGS 441In addition to the bugs documented in 442.Xr scanf 3 , 443.Fn wscanf 444does not support the 445.Dq Li A-Z 446notation for specifying character ranges with the character 447class conversion 448.Pq Sq Cm %[ . 449