格式字符 | 說明 |
%a、%A | 讀入一個浮點值(僅C99有效) |
%f 、
%F、
%e、
%E、
%g 、
%G
|
讀入一個浮點數
|
%c、%C | 讀入一個字符 |
%d | 讀入十進制整數 |
%s | 讀入一個字符串 |
%p | 讀入一個指針 |
%u |
讀入一個無符號十進制整數
|
%n | 至此已讀入值的等價字符數 |
%[] | 掃描字符集合 |
%% | 讀%符號 |
%o | 讀入八進制整數 |
%x 、%X | 讀入十六進制整數 |
%i | 讀入十進制,八進制,十六進制整數 |
sub-specifier | description |
---|---|
* | An optional starting asterisk indicates that the data is to be read from the stream but ignored (i.e. it is not stored in the location pointed by an argument). 注:加上*可將該位置數據忽略 |
width | Specifies the maximum number of characters to be read in the current reading operation (optional). 注:好比填入7.3,表示整數部分寬度爲7,小數部分只讀到第3位;也能夠不填,不填則將對應數據不帶舍入地讀入 |
length | One of hh, h, l, ll, j, z, t, L (optional). This alters the expected type of the storage pointed by the corresponding argument (see the last table). |
specifier | Description | Characters extracted |
---|---|---|
i, u | Integer | Any number of digits, optionally preceded by a sign (+ or -). Decimal digits assumed by default (0-9), but a 0 prefix introduces octal digits (0-7), and 0x hexadecimal digits (0-f). |
d | Decimal integer (十進制數) |
Any number of decimal digits (0-9), optionally preceded by a sign (+ or -). |
o | Octal integer | Any number of octal digits (0-7), optionally preceded by a sign (+ or -). |
x | Hexadecimal integer (16進制數) | Any number of hexadecimal digits (0-9, a-f, A-F), optionally preceded by 0x or 0X, and all optionally preceded by a sign (+ or -). |
f, e, g | Floating point number (浮點數) |
A series of decimal digits, optionally containing a decimal point, optionally preceeded by a sign (+ or -) and optionally followed by the e or E character and a decimal integer (or some of the other sequences supported by strtod). Implementations complying with C99 also support hexadecimal floating-point format when preceded by 0x or 0X . |
a | ||
c | Character | The next character. If a width other than 1 is specified, the function reads exactlywidth characters and stores them in the successive locations of the array passed as argument. No null character is appended at the end. |
s | String of characters | Any number of non-whitespace characters, stopping at the first whitespacecharacter found. A terminating null character is automatically added at the end of the stored sequence. |
p | Pointer address | A sequence of characters representing a pointer. The particular format used depends on the system and library implementation, but it is the same as the one used to format %p in fprintf. |
[characters] | Scanset | Any number of the characters specified between the brackets. A dash (-) that is not the first character may produce non-portable behavior in some library implementations. |
[^characters] | Negated scanset | Any number of characters none of them specified as characters between the brackets. |
n | Count | No input is consumed. The number of characters read so far from stream is stored in the pointed location. |
% | % | A % followed by another % matches a single %. |
specifiers | |||||||
---|---|---|---|---|---|---|---|
length | d i | u o x | f e g a | c s [] [^] | p | n | |
(none) | int* | unsigned int* | float* | char* | void** | int* | |
hh | signed char* | unsigned char* | signed char* | ||||
h | short int* | unsigned short int* | short int* | ||||
l | long int* | unsigned long int* | double* | wchar_t* | long int* | ||
ll | long long int* | unsigned long long int* | long long int* | ||||
j | intmax_t* | uintmax_t* | intmax_t* | ||||
z | size_t* | size_t* | size_t* | ||||
t | ptrdiff_t* | ptrdiff_t* | ptrdiff_t* | ||||
L | long double* |