
SCANF(3)                   UNIX Programmer's Manual                   SCANF(3)

NNAAMMEE
     ssccaannff, ffssccaannff, ssssccaannff, vvssccaannff, vvssssccaannff, vvffssccaannff - input format conversion

SSYYNNOOPPSSIISS
     ##iinncclluuddee <<ssttddiioo..hh>>

     _i_n_t
     ssccaannff(_c_o_n_s_t _c_h_a_r _*_f_o_r_m_a_t, _._._.)

     _i_n_t
     ffssccaannff(_F_I_L_E _*_s_t_r_e_a_m, _c_o_n_s_t _c_h_a_r _*_f_o_r_m_a_t, _._._.)

     _i_n_t
     ssssccaannff(_c_o_n_s_t _c_h_a_r _*_s_t_r, _c_o_n_s_t _c_h_a_r _*_f_o_r_m_a_t, _._._.)

     ##iinncclluuddee <<ssttddaarrgg..hh>>

     _i_n_t
     vvssccaannff(_c_o_n_s_t _c_h_a_r _*_f_o_r_m_a_t, _v_a___l_i_s_t _a_p)

     _i_n_t
     vvssssccaannff(_c_o_n_s_t _c_h_a_r _*_s_t_r, _c_o_n_s_t _c_h_a_r _*_f_o_r_m_a_t, _v_a___l_i_s_t _a_p)

     _i_n_t
     vvffssccaannff(_F_I_L_E _*_s_t_r_e_a_m, _c_o_n_s_t _c_h_a_r _*_f_o_r_m_a_t, _v_a___l_i_s_t _a_p)

DDEESSCCRRIIPPTTIIOONN
     The ssccaannff() family of functions scans input according to a _f_o_r_m_a_t as de-
     scribed below.  This format may contain _c_o_n_v_e_r_s_i_o_n _s_p_e_c_i_f_i_e_r_s; the re-
     sults from such conversions, if any, are stored through the _p_o_i_n_t_e_r argu-
     ments.  The ssccaannff() function reads input from the standard input stream
     _s_t_d_i_n, ffssccaannff() reads input from the stream pointer _s_t_r_e_a_m, and ssssccaannff()
     reads its input from the character string pointed to by _s_t_r. The
     vvffssccaannff() function is analogous to vfprintf(3) and reads input from the
     stream pointer _s_t_r_e_a_m using a variable argument list of pointers (see
     stdarg(3)).  The vvssccaannff() function scans a variable argument list from
     the standard input and the vvssssccaannff() function scans it from a string;
     these are analogous to the vvpprriinnttff() and vvsspprriinnttff() functions respective-
     ly.  Each successive _p_o_i_n_t_e_r argument must correspond properly with each
     successive conversion specifier (but see `suppression' below).  All con-
     versions are introduced by the %% (percent sign) character.  The _f_o_r_m_a_t
     string may also contain other characters.  White space (such as blanks,
     tabs, or newlines) in the _f_o_r_m_a_t string match any amount of white space,
     including none, in the input.  Everything else matches only itself.
     Scanning stops when an input character does not match such a format char-
     acter.  Scanning also stops when an input conversion cannot be made (see
     below).

CCOONNVVEERRSSIIOONNSS
     Following the %% character introducing a conversion there may be a number
     of _f_l_a_g characters, as follows:

     **       Suppresses assignment.  The conversion that follows occurs as
             usual, but no pointer is used; the result of the conversion is
             simply discarded.

     hh       Indicates that the conversion will be one of ddiioouuxx or nn and the
             next pointer is a pointer to a _s_h_o_r_t _i_n_t (rather than _i_n_t).

     ll       Indicates either that the conversion will be one of ddiioouuxx or nn
             and the next pointer is a pointer to a _l_o_n_g _i_n_t (rather than
             _i_n_t), or that the conversion will be one of eeffgg and the next

             pointer is a pointer to _d_o_u_b_l_e (rather than _f_l_o_a_t).

     LL       Indicates that the conversion will be eeffgg and the next pointer is
             a pointer to _l_o_n_g _d_o_u_b_l_e. (This type is not implemented; the LL
             flag is currently ignored.)

     In addition to these flags, there may be an optional maximum field width,
     expressed as a decimal integer, between the %% and the conversion.  If no
     width is given, a default of `infinity' is used (with one exception, be-
     low); otherwise at most this many characters are scanned in processing
     the conversion.  Before conversion begins, most conversions skip white
     space; this white space is not counted against the field width.

     The following conversions are available:

     %%     Matches a literal `%'.  That is, `%%' in the format string matches
           a single input `%' character.  No conversion is done, and assign-
           ment does not occur.

     dd     Matches an optionally signed decimal integer; the next pointer must
           be a pointer to _i_n_t.

     DD     Equivalent to ld;  this exists only for backwards compatibility.

     ii     Matches an optionally signed integer; the next pointer must be a
           pointer to _i_n_t. The integer is read in base 16 if it begins with
           `0x' or `0X', in base 8 if it begins with `0', and in base 10 oth-
           erwise.  Only characters that correspond to the base are used.

     oo     Matches an octal integer; the next pointer must be a pointer to
           _u_n_s_i_g_n_e_d _i_n_t.

     OO     Equivalent to lo;  this exists for backwards compatibility.

     uu     Matches an optionally signed decimal integer; the next pointer must
           be a pointer to _u_n_s_i_g_n_e_d _i_n_t.

     xx     Matches an optionally a signed hexadecimal integer; the next point-
           er must be a pointer to _u_n_s_i_g_n_e_d _i_n_t.

     XX     Equivalent to llxx; this violates the ANSI C3.159-1989 (``ANSI C''),
           but is backwards compatible with previous UNIX systems.

     ff     Matches an optionally signed floating-point number; the next point-
           er must be a pointer to _f_l_o_a_t.

     ee     Equivalent to ff.

     gg     Equivalent to ff.

     EE     Equivalent to llff; this violates the ANSI C3.159-1989 (``ANSI C''),
           but is backwards compatible with previous UNIX systems.

     FF     Equivalent to llff; this exists only for backwards compatibility.

     ss     Matches a sequence of non-white-space characters; the next pointer
           must be a pointer to _c_h_a_r, and the array must be large enough to
           accept all the sequence and the terminating NUL character.  The in-
           put string stops at white space or at the maximum field width,
           whichever occurs first.

     cc     Matches a sequence of _w_i_d_t_h count characters (default 1); the next
           pointer must be a pointer to _c_h_a_r, and there must be enough room
           for all the characters (no terminating NUL is added).  The usual
           skip of leading white space is suppressed.  To skip white space

           first, use an explicit space in the format.

     [[     Matches a nonempty sequence of characters from the specified set of
           accepted characters; the next pointer must be a pointer to _c_h_a_r,
           and there must be enough room for all the characters in the string,
           plus a terminating NUL character.  The usual skip of leading white
           space is suppressed.  The string is to be made up of characters in
           (or not in) a particular set; the set is defined by the characters
           between the open bracket [ character and a close bracket ] charac-
           ter.  The set _e_x_c_l_u_d_e_s those characters if the first character af-
           ter the open bracket is a circumflex ^^. To include a close bracket
           in the set, make it the first character after the open bracket or
           the circumflex; any other position will end the set.  The hyphen
           character -- is also special; when placed between two other charac-
           ters, it adds all intervening characters to the set.  To include a
           hyphen, make it the last character before the final close bracket.
           For instance, `[^]0-9-]' means the set `everything except close
           bracket, zero through nine, and hyphen'.  The string ends with the
           appearance of a character not in the (or, with a circumflex, in)
           set or when the field width runs out.

     pp     Matches a pointer value (as printed by `%p' in printf(3));  the
           next pointer must be a pointer to _v_o_i_d.

     nn     Nothing is expected; instead, the number of characters consumed
           thus far from the input is stored through the next pointer, which
           must be a pointer to _i_n_t. This is _n_o_t a conversion, although it can
           be suppressed with the ** flag.

     For backwards compatibility, other conversion characters (except `\0')
     are taken as if they were `%d' or, if uppercase, `%ld', and a `conver-
     sion' of `%\0' causes an immediate return of EOF. The FF and XX conversions
     will be changed in the future to conform to the ANSI C standard, after
     which they will act like ff and xx respectively.

RREETTUURRNN VVAALLUUEESS
     These functions return the number of input items assigned, which can be
     fewer than provided for, or even zero, in the event of a matching fail-
     ure.  Zero indicates that, while there was input available, no conver-
     sions were assigned; typically this is due to an invalid input character,
     such as an alphabetic character for a `%d' conversion.  The value EOF is
     returned if an input failure occurs before any conversion such as an end-
     of-file occurs. If an error or end-of-file occurs after conversion has
     begun, the number of conversions which were successfully completed is re-
     turned.

SSEEEE AALLSSOO
     strtol(3),  strtoul(3),  getc(3),  printf(3)

SSTTAANNDDAARRDDSS
     The functions ffssccaannff(), ssccaannff(), and ssssccaannff() conform to ANSI C3.159-1989
     (``ANSI C'').

HHIISSTTOORRYY
     The functions vvssccaannff(), vvssssccaannff() and vvffssccaannff() are new to this release.

BBUUGGSS
     The current situation with %%FF and %%XX conversions is unfortunate.

     All of the backwards compatibility formats will be removed in the future.

BSD Experimental                 June 29, 1991                               3




