United States-English |
|
|
HP-UX Reference > Ffwscanf(3C)HP-UX 11i Version 3: February 2007 |
|
NAMEfwscanf(), wscanf(), swscanf() — convert formatted wide-character input SYNOPSIS#include <stdio.h> #include <wchar.h> int fwscanf(FILE *__restrict stream, const wchar_t *__restrict format, ... ); int wscanf(const wchar_t *__restrict format, ... ); int swscanf(const wchar_t *__restrict s, const wchar_t *__restrict format, ... ); DESCRIPTIONThe fwscanf() function reads from the named input stream. The wscanf() function reads from the standard input stream stdin. The swscanf() reads from the wide-character string s. Each function reads wide-characters, interprets them according to a format, and stores the results in its arguments. Each expects, as arguments, a control wide-character string format described below, and a set of pointer arguments indicating where the converted input should be stored. The result is undefined if there are insufficient arguments for the format. If the format is exhausted while arguments remain, the excess arguments are evaluated but are otherwise ignored. Conversions can be applied to the nth argument after the format in the argument list, rather than to the next unused argument. In this case, the conversion wide-character % (see below) is replaced by the sequence %n$, where n is a decimal integer in the range [1,{NL_ARGMAX}]. This feature provides for the definition of format wide-character strings that select arguments in an order appropriate to specific languages. In format wide-character strings containing the %n$ form of conversion specifications, it is unspecified whether numbered arguments in the argument list can be referenced from the format wide-character string more than once. The format can contain either form of a conversion specification, that is, % or %n$, but the two forms cannot normally be mixed within a single format wide-character string. The only exception to this is that %% or %* can be mixed with the %n$ form. The fwscanf() function in all its forms allows for detection of a language-dependent radix character in the input string, encoded as a wide-character value. The radix character is defined in the program's locale (category LC_NUMERIC). In the POSIX locale, or in a locale where the radix character is not defined, the radix character defaults to a period (.). The format is a wide-character string composed of zero or more directives. Each directive is composed of one of the following:
Each conversion specification is introduced by a % or the sequence %n$ after which the following appear in sequence:
The fwscanf() functions execute each directive of the format in turn. If a directive fails, as detailed below, the function returns. Failures are described as input failures (due to the unavailability of input bytes) or matching failures (due to inappropriate input). A directive composed of one or more white-space wide-characters is executed by reading input until no more valid input can be read, or up to the first wide-character which is not a white-space wide-character, which remains unread. A directive that is an ordinary wide-character is executed as follows. The next wide-character is read from the input and compared with the wide-character that comprises the directive; if the comparison shows that they are not equivalent, the directive fails, and the differing and subsequent wide-characters remain unread. A directive that is a conversion specification defines a set of matching input sequences, as described below for each conversion wide-character. A conversion specification is executed in the following steps: Input white-space wide-characters (as specified by iswspace()) are skipped, unless the conversion specification includes a [, c or n conversion character. An item is read from the input, unless the conversion specification includes an n conversion wide-character. An input item is defined as the longest sequence of input wide-characters, not exceeding any specified field width, which is an initial subsequence of a matching sequence. The first wide-character, if any, after the input item remains unread. If the length of the input item is 0, the execution of the conversion specification fails; this condition is a matching failure, unless end-of-file, an encoding error, or a read error prevented input from the stream, in which case it is an input failure. Except in the case of a % conversion wide-character, the input item (or, in the case of a %n conversion specification, the count of input wide-characters) is converted to a type appropriate to the conversion wide-character. If the input item is not a matching sequence, the execution of the conversion specification fails; this condition is a matching failure. Unless assignment suppression was indicated by a *, the result of the conversion is placed in the object pointed to by the first argument following the format argument that has not already received a conversion result if the conversion specification is introduced by %, or in the nth argument if introduced by the wide-character sequence %n$. If this object does not have an appropriate type, or if the result of the conversion cannot be represented in the space provided, the behavior is undefined. The following conversion wide-characters are valid:
If the fwprintf() family of functions generates character string representations for infinity and NaN (a 7858 symbolic entity encoded in floating-point format) to support the ANSI/IEEE Std 754:1985 standard, the fwscanf() family of functions will recognize them as input.
Otherwise, the corresponding argument must be a pointer to an array of wchar_t large enough to accept the sequence and the terminating null wide-character, which will be added automatically.
If an l (ell) qualifier is present, the corresponding argument must be a pointer to an array of wchar_t large enough to accept the sequence and the terminating null wide-character, which will be added automatically. The conversion specification includes all subsequent wide characters in the format string up to and including the matching right square bracket ( ]). The wide-characters between the square brackets (the scanlist) comprise the scanset, unless the wide-character after the left square bracket is a circumflex ( ^), in which case the scanset contains all wide-characters that do not appear in the scanlist between the circumflex and the right square bracket. If the conversion specification begins with [] or [^], the right square bracket is included in the scanlist and the next right square bracket is the matching right square bracket that ends the conversion specification; otherwise the first right square bracket is the one that ends the conversion specification. If a - is in the scanlist and is not the first wide-character, nor the second where the first wide-character is a ^, nor the last wide-character, the behavior is implementation-dependent.
If a conversion specification is invalid, the behavior is undefined. The conversion characters A, E, F, G and X are also valid and behave the same as, respectively, a, e, f, g and x. If end-of-file is encountered during input, conversion is terminated. If end-of-file occurs before any wide-characters matching the current conversion specification (except for %n) have been read (other than leading white-space, where permitted), execution of the current conversion specification terminates with an input failure. Otherwise, unless execution of the current conversion specification is terminated with a matching failure, execution of the following conversion specification (if any) is terminated with an input failure. Reaching the end of the string in swscanf() is equivalent to encountering end-of-file for fwscanf(). If conversion terminates on a conflicting input, the offending input is left unread in the input. Any trailing white space (including newline) is left unread unless matched by a conversion specification. The success of literal matches and suppressed assignments is only directly determinable via the %n conversion specification. The fwscanf() and wscanf() functions may mark the st_atime field of the file associated with stream for update. The st_atime field will be marked for update by the first successful execution of fgetc(), fgetwc(), fgets(), fgetws(), fread(), getc(), getwc(), getchar(), getwchar(), gets(), fscanf() or fwscanf() using stream that returns data not supplied by a prior call to ungetc(). APPLICATION USAGEAfter fwscanf() or wscanf() is applied to a stream, the stream becomes wide-oriented (see orientation(5)). In format strings containing the % form of conversion specifications, each argument in the argument list is used exactly once. The prototypes of these functions are available to applications if they are:
RETURN VALUEUpon successful completion, these functions return the number of successfully matched and assigned input items; this number can be 0 in the event of an early matching failure. If the input ends before the first matching failure or conversion, EOF is returned. If a read error occurs the error indicator for the stream is set, EOF is returned, and errno is set to indicate the error. ERRORSFor the conditions under which the fwscanf() functions will fail and may fail, refer to fgetwc(). In addition, fwscanf() may fail if:
In addition, fwscanf() may fail if:
In addition, wscanf() may fail if:
EXAMPLESThe call: int i, n; float x; char name[50]; n = wscanf(L"%d%f%s", &i, &x, name); with the input line: 25 54.32E-1 Hamster will assign to n the value 3, to i the value 25, x the value 5.432, and name will contain the string Hamster. The call: int i; float x; char name[50]; (void)wscanf(L"%2d%f%*d %[0123456789]", &i, &x, name); with input: 56789 0123 56a72 will assign 56 to i, 789.0 to x, skip 0123, and place the string 56 in name. The next call to getchar() will return the character a. SEE ALSOfwprintf(3C), getwc(3C), setlocale(3C), wcstod(3C), wcstol(3C), wcrtomb(3C), wcstoul(3C), langinfo(5), orientation(5), thread_safety(5), glossary(9). |
Printable version | ||
|