📄 scanfs.gml
字号:
or the corresponding unsigned integer type.
.bull
"t" causes an "n" (read length assignment) operation to assign the
number of characters that have been read to an object of type
.id ptrdiff_t.
.bull
.ix '__int64'
"I64" causes a "d", "i", "o", "u" or "x" (integer) conversion to
assign the converted value to an object of type
.id __int64
or
.id unsigned __int64
(e.g., %I64d).
.bull
.ix 'long double'
"L" causes an "e", "f" or "g" (floating-point) conversion to assign
the converted value to an object of type
.id long double.
.endbull
.np
The valid conversion type specifiers are:
.begnote $setptnt 5
.note 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
.id char
is sufficient.
.note C
A sequence of multibyte characters in the input stream is matched.
Each multibyte character is converted to a wide character of type
.id 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
.id 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
.id wchar_t
is sufficient.
.note 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
.id int.
.note e, f, g
A floating-point number, consisting of an optional sign ("+" or
"&minus."), 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
.id float.
.note i
An optional sign, followed by an octal, decimal or hexadecimal
constant is matched.
An octal constant consists of "0" and zero or more octal digits.
A decimal constant consists of a non-zero decimal digit and zero or
more decimal digits.
A hexadecimal constant consists of the characters "0x" or "0X"
followed by one or more (upper- or lowercase) hexadecimal digits.
The argument is assumed to point to an object of type
.id int.
.note n
No input data is processed.
Instead, the number of characters that have already been read is
assigned to the object of type
.id unsigned int
that is pointed to by the argument.
The number of items that have been scanned and assigned (the return
value) is not affected by the "n" conversion type specifier.
.note o
An octal integer, consisting of an optional sign, followed by one or
more (zero or non-zero) octal digits, is matched.
The argument is assumed to point to an object of type
.id int.
.note p
A hexadecimal integer, as described for "x" conversions below, is
matched.
The converted value is further converted to a value of type
.id void*
and then assigned to the object pointed to by the argument.
.note s
A sequence of non-white-space characters is matched.
The argument is assumed to point to the first element of a character
array of sufficient size to contain the sequence and a terminating
null character, which is added by the conversion operation.
.note S
A sequence of multibyte characters is matched.
None of the multibyte characters in the sequence may be single byte
white-space characters.
Each multibyte character is converted to a wide character.
The argument is assumed to point to the first element of an array of
.id wchar_t
of sufficient size to contain the sequence and a terminating null wide
character, which is added by the conversion operation.
.note u
An unsigned decimal integer, consisting of one or more decimal digits,
is matched.
The argument is assumed to point to an object of type
.id unsigned int.
.note x
A hexadecimal integer, consisting of an optional sign, followed by an
optional prefix "0x" or "0X", followed by one or more (upper- or
lowercase) hexadecimal digits, is matched.
The argument is assumed to point to an object of type
.id int.
.note [c1c2...]
The longest, non-empty sequence of characters, consisting of any of
the characters
.mono c1, c2, ...
called the
.us scanset,
in any order, is matched.
.mono c1
cannot be the caret character ('^').
If
.mono c1
is "]", that character
is considered to be part of the scanset and a second "]"
is required to end the format directive.
The argument is assumed to point to the first element of a character
array of sufficient size to contain the sequence and a terminating
null character, which is added by the conversion operation.
.note [^c1c2...]
The longest, non-empty sequence of characters, consisting of any
characters
.us other than
the characters between the "^" and "]", is matched.
As with the preceding conversion, if
.mono c1
is "]", it is considered to be part of the scanset and a second "]"
ends the format directive.
The argument is assumed to point to the first element of a character
array of sufficient size to contain the sequence and a terminating
null character, which is added by the conversion operation.
.np
For example, the specification
.mono %[^\n]
will match an entire input line up to but not including the newline
character.
.endnote
.np
A conversion type specifier of "%" is treated as a single ordinary
character that matches a single "%" character in the input data.
A conversion type specifier other than those listed above causes
scanning to terminate and the function to return.
.np
Conversion type specifiers "E", "F", "G", "X" have meaning identical to
their lowercase equivalents.
.np
The line
.blkcode begin
scanf( "%s%*f%3hx%d", name, &hexnum, &decnum )
.blkcode end
.blktext begin
with input
.blktext end
.blkcode begin
some_string 34.555e-3 abc1234
.blkcode end
.blktext begin
will copy
.mono "some_string"
into the array
.id name,
skip
.mono 34.555e-3
..ct ,
assign
.mono 0xabc
to
.id hexnum
and
.id 1234
to
.id decnum.
The return value will be 3.
.np
The program
.blktext end
.blkcode begin
#include <stdio.h>
void main( void )
{
char string1[80], string2[80];
scanf( "%[abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWZ ]%*2s%[^\n]",
string1, string2 );
printf( "%s\n%s\n", string1, string2 );
}
.blkcode end
.blktext begin
with input
.blktext end
.blkcode begin
They may look alike, but they don't perform alike.
.blkcode end
.blktext begin
will assign
.blktext end
.blkcode begin
"They may look alike"
.blkcode end
.blktext begin
to
.id string1,
skip the comma (the
.mono "%*2s"
will match only the comma; the following blank terminates that field),
and assign
.blktext end
.blkcode begin
" but they don't perform alike."
.blkcode end
.blktext begin
to
.id string2.
.blktext end
.oldtext end
.if &farfnc eq 0 .do begin
.class ISO C90
The I64 modifier is an extension to ISO C.
.do end
.el .do begin
.class ISO C90
The N, W pointer size modifiers and the I64 modifier are extensions to ISO C.
.do end
.system
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -