## 1. Scanf 的基本用法

scanf 是 C 语言标准输入流（stdio）里面提供的一个输入数据的函数，对于不同的数据类型可以用用不同的格式来读取，然后储存在变量之中。

specifier Description Characters extracted
i 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).Signed argument.
d or u Decimal integer Any number of decimal digits (0-9), optionally preceded by a sign (+ or -).d is for a signed argument, and u for an unsigned.
o Octal integer Any number of octal digits (0-7), optionally preceded by a sign (+ or -).Unsigned argument.
x Hexadecimal integer 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 -).Unsigned argument.
f, e, g ,a 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.
c Character The next character. If a width other than 1 is specified, the function reads exactly width 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 whitespace character 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 stdin is stored in the pointed location.
% % A % followed by another % matches a single %.

## 总结

[^eof]:

Scanf and EOF (End Of F 文件末)自己在本地测试时，也能输入 EOF。Windows 中，先输入数据回车，按下Ctrl+Z，命令行里出现^z，回车，就会写入 EOF。Linux 中，先输入数据再回车，按下Ctrl+d，就会写入 EOF。

[^other]: 我们还可以利用其它的函数来读取，比如，用 gets（）读取字符串，遇\n 结束，会把\n 读取，转换为\0，输入流中不再有\n。

[^strtok]:

strtok

0%