这个和unix下的正则表达式很相似
[ ]表示选择,^表示非
这里的*是忽略
The format specification controls how the arguments are converted for assignment. The percent sign (%) indicates the start of a conversion specification. Except for the conversion specifications and white space, other characters in the format have to match the input. If a character doesn't match, processing stops, leaving the remainder of the input unread.
There are three optional components to a conversion specification, shown in square brackets below:
%[*][fldwidth][lenmodifier]convtype
The optional leading asterisk is used to suppress conversion. Input is converted as specified by the rest of the conversion specification, but the result is not stored in an argument.
The fldwidth component specifies the maximum field width in characters. The lenmodifier component specifies the size of the argument to be initialized with the result of the conversion. The same length modifiers supported by the printf family of functions are supported by the scanf family of functions (see Figure 5.8 for a list of the length modifiers).
The convtype field is similar to the conversion type field used by the printf family, but there are some differences. One difference is that results that are stored in unsigned types can optionally be signed on input. For example, 1 will scan as 4294967295 into an unsigned integer. Figure 5.10 summarizes the conversion types supported by the scanf family of functions.
Conversion
type
Description
d
signed decimal, base 10
i
signed decimal, base determined by format of input
o
unsigned octal (input optionally signed)
u
unsigned decimal, base 10 (input optionally signed)
x
unsigned hexadecimal (input optionally signed)
a,A,e,E,f,F,g,G
floating-point number
c
character (with l length modifier, wide character)
s
string (with l length modifier, wide character string)
[
matches a sequence of listed characters, ending with ]
[^
matches all characters except the ones listed, ending with ]
p
pointer to a void
n
pointer to a signed integer into which is written the number of characters read so far
%
a % character
C
wide character (an XSI extension, equivalent to lc)
S
wide character string (an XSI extension, equivalent to ls)