Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C Library Reference - <u>synopsis:</u> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Synopsis:
    #include <stdio.h>
    int scanf( const char *format, ... );
    #include <wchar.h>
    int wscanf( const wchar_t *format, ... );

Description:
    The scanf function scans input from the file designated by  stdin under
    control of the argument format.  The format string is described below.
     Following the format string is the list of addresses of items to
    receive values.

    The wscanf function is identical to scanf except that it accepts a
    wide-character string argument for format.

Returns:
    The scanf function returns  EOF when the scanning is terminated by
    reaching the end of the input stream.  Otherwise, the number of input
    arguments for which values were successfully scanned and stored is
    returned.

Example:
    To scan a date in the form "Saturday April 18 1987":

    #include <stdio.h>

    void main()
      {
        int day, year;
        char weekday[10], month[12];

        scanf( "%s %s %d %d", weekday, month, &day, &year );
      }

Format Control String:
    The format control string consists of zero or more format directives
    that specify acceptable input file data.  Subsequent arguments are
    pointers to various types of objects that are assigned values as the
    format string is processed.

    A format directive can be a sequence of one or more white-space
    characters, an ordinary character, or a conversion specifier.  An
    ordinary character in the format string is any character, other than a
    white-space character or the percent character (%), that is not part of
    a conversion specifier.  A conversion specifier is a sequence of
    characters in the format string that begins with a percent character (%)
    and is followed, in sequence, by the following:

     .  an optional assignment suppression indicator:  the asterisk
        character (*);
     .  an optional decimal integer that specifies the maximum field width
        to be scanned for the conversion;
     .  an optional pointer-type specification:  one of "N" or "F";
     .  an optional type length specification:  one of "h", "l", "L" or
        "I64";
     .  a character that specifies the type of conversion to be performed:
         one of the characters "cCdefginopsSux[".

    As each format directive in the format string is processed, the
    directive may successfully complete, fail because of a lack of input
    data, or fail because of a matching error as defined by the particular
    directive.  If end-of-file is encountered on the input data before any
    characters that match the current directive have been processed (other
    than leading white-space where permitted), the directive fails for lack
    of data.  If end-of-file occurs after a matching character has been
    processed, the directive is completed (unless a matching error occurs),
    and the function returns without processing the next directive.  If a
    directive fails because of an input character mismatch, the character is
    left unread in the input stream.  Trailing white-space characters,
    including new-line characters, are not read unless matched by a
    directive.  When a format directive fails, or the end of the format
    string is encountered, the scanning is completed and the function
    returns.

    When one or more white-space characters (space " ", horizontal tab "\t",
    vertical tab "\v", form feed "\f", carriage return "\r", new line or
    linefeed "\n") occur in the format string, input data up to the first
    non-white-space character is read, or until no more data remains.  If no
    white-space characters are found in the input data, the scanning is
    complete and the function returns.

    An ordinary character in the format string is expected to match the same
    character in the input stream.

    A conversion specifier in the format string is processed as follows:

     .  for conversion types other than "[", "c", "C" and "n", leading
        white-space characters are skipped
     .  for conversion types other than "n", all input characters, up to any
        specified maximum field length, that can be matched by the
        conversion type are read and converted to the appropriate type of
        value; the character immediately following the last character to be
        matched is left unread; if no characters are matched, the format
        directive fails
     .  unless the assignment suppression indicator ("*") was specified, the
        result of the conversion is assigned to the object pointed to by the
        next unused argument (if assignment suppression was specified, no
        argument is skipped); the arguments must correspond in number, type
        and order to the conversion specifiers in the format string

    A pointer-type specification is used to indicate the type of pointer
    used to locate the next argument to be scanned:

    F
        pointer is a far pointer

    N
        pointer is a near pointer

    The pointer type defaults to that used for data in the memory model for
    which the program has been compiled.

    A type length specifier affects the conversion as follows:

     .  "h" causes a "d", "i", "o", "u" or "x" (integer) conversion to
        assign the converted value to an object of type short int or
        unsigned short int.
     .  "h" causes an "f" conversion to assign a fixed-point number to an
        object of type long consisting of a 16-bit signed integer part and a
        16-bit unsigned fractional part.  The integer part is in the high 16
        bits and the fractional part is in the low 16 bits.


             struct fixpt {
                 unsigned short fraction; /* Intel architecture! */
                   signed short integral;
             };

             struct fixpt foo1 =
               { 0x8000, 1234 }; /* represents 1234.5 */
             struct fixpt foo2 =
               { 0x8000, -1 };   /* represents -0.5 (-1+.5) */
     .  "h" causes an "n" (read length assignment) operation to assign the
        number of characters that have been read to an object of type
        unsigned short int.
     .  "h" causes an "s" operation to convert the input string to an ASCII
        character string.  For scanf, this specifier is redundant.  For
        wscanf, this specifier is required if the wide character input
        string is to be converted to an ASCII character string; otherwise it
        will not be converted.
     .  "l" causes a "d", "i", "o", "u" or "x" (integer) conversion to
        assign the converted value to an object of type long int or unsigned
        long int.
     .  "l" causes an "n" (read length assignment) operation to assign the
        number of characters that have been read to an object of type
        unsigned long int.
     .  "l" causes an "e", "f" or "g" (floating-point) conversion to assign
        the converted value to an object of type double.
     .  "l" or "w" cause an "s" operation to convert the input string to a
        wide character string.  For scanf, this specifier is required if the
        input ASCII string is to be converted to a wide character string;
        otherwise it will not be converted.
     .  "L" causes a "d", "i", "o", "u" or "x" (integer) conversion to
        assign the converted value to an object of type __int64 or unsigned
        __int64 (e.g., %Ld).
     .  "I64" causes a "d", "i", "o", "u" or "x" (integer) conversion to
        assign the converted value to an object of type __int64 or unsigned
        __int64 (e.g., %I64d).  The "L" specifier provides the same
        functionality.
     .  "L" causes an "e", "f" or "g" (floating-point) conversion to assign
        the converted value to an object of type long double.

    The valid conversion type specifiers are:

    c
        Any sequence of characters in the input stream of the length
        specified by the field width, or a single character if no field
        width is specified, is matched.  The argument is assumed to point to
        the first element of a character array of sufficient size to contain
        the sequence, without a terminating null character ('\0').  For a
        single character assignment, a pointer to a single object of type
        char is sufficient.

    C
        A sequence of multibyte characters in the input stream is matched.
         Each multibyte character is converted to a wide character of type
        wchar_t.  The number of wide characters matched is specified by the
        field width (1 if no field width is specified).  The argument is
        assumed to point to the first element of an array of wchar_t of
        sufficient size to contain the sequence.  No terminating null wide
        character (L'\0') is added.  For a single wide character assignment,
        a pointer to a single object of type wchar_t is sufficient.

    d
        A decimal integer, consisting of an optional sign, followed by one
        or more decimal digits, is matched.  The argument is assumed to
        point to an object of type int.

    e, f, g
        A floating-point number, consisting of an optional sign ("+" or
        "-"), followed by one or more decimal digits, optionally containing
        a decimal-point character, followed by an optional exponent of the
        form "e" or "E", an optional sign and one or more decimal digits, is
        matched.  The exponent, if present, specifies the power of ten by
        which the decimal fraction is multiplied.  The argument is assumed
        to point to an object of type float.

    i
        An optional sign, followed by an octal, decimal or hexadecimal

See Also:
    cscanf, fscanf, sscanf, vcscanf, vfscanf, vscanf, vsscanf

See Also: cscanf vcscanf

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson