1
|
int
sscanf
(
const
char
*buffer,
const
char
*format, [ argument ] ... );
|
例程 | 必须的头文件 |
---|---|
sscanf |
< stdio.h>
|
_sscanf_l | |
swscanf |
< stdio.h>
|
_swscanf_l |
1
2
3
|
char
buf[512] = ;
sscanf
(
"123456 "
,
"%s"
, buf);
printf
(
"%s\n"
, buf);
|
1
2
|
sscanf
(
"123456 "
,
"%4s"
, buf);
printf
(
"%s\n"
, buf);
|
1
2
|
sscanf
(
"123456 abcdedf"
,
"%[^ ]"
, buf);
printf
(
"%s\n"
, buf);
|
1
2
|
sscanf
(
"123456abcdedfBCDEF"
,
"%[1-9a-z]"
, buf);
printf
(
"%s\n"
, buf);
|
1
2
|
sscanf
(
"123456abcdedfBCDEF"
,
"%[^A-Z]"
, buf);
printf
(
"%s\n"
, buf);
|
1
2
|
sscanf
(
"iios/12DDWDFF@122"
,
"%*[^/]/%[^@]"
, buf);
printf
(
"%s\n"
, buf);
|
1
2
|
sscanf
(“hello, world”,
"%*s%s"
, buf);
printf
(
"%s\n"
, buf);
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
//Compiled with Visual Studio 2015.
//================Original File===================*/
// crt_sscanf.c
// compile with: /W3
// This program uses sscanf to read data items
// from a string named tokenstring, then displays them. #
include
int
main(
void
) {
char
tokenstring[] =
"15 12 14..."
;
char
s[81];
char
c;
int
i;
float
fp;
// Input various data from tokenstring:
// max 80 character string:
sscanf
( tokenstring,
"%80s"
, s );
// C4996
sscanf
( tokenstring,
"%c"
, &c );
// C4996
sscanf
( tokenstring,
"%d"
, &i );
// C4996
sscanf
( tokenstring,
"%f"
, &fp );
// C4996
// Note: sscanf is deprecated; consider using sscanf_s instead
// Output the data read
printf
(
"String = %s\n"
, s );
printf
(
"Character = %c\n"
, c );
printf
(
"Integer: = %d\n"
, i );
printf
(
"Real: = %f\n"
, fp );
}
|
1
|
String = 15 Character = 1 Integer: = 15 Real: = 15.000000
|