1) scanf function, is a standard input function
is a blocking function: When using scanf, the program waits for user input, and if you do not enter the content, the program no longer executes
Function: Receive the content that is lost from the keyboard
2) Use the format:
Compare printf
printf ("Format control string", variable list);
scanf ("Format control string", "Address" list of variables)
The address of the variable: the first address of the variable
method to get the first address of a variable: & variable Name
printf ("A =%d\n", a);
scanf ("%d", &a);
3) Format Control
%d receives an integer
%f Receive real numbers
%c receives characters
...
4) The use of scanf function attention point
(1) When using the SCANF function to receive an "integer", enter a space before entering the Data tab return
The scanf function ignores
(2) scanf function when entering data, use carriage return as Terminator
(3) But when you enter a character, it's a bit of a problem.
Example 1
scanf ("%d%d%d", &a,&b,&c);
If you enter in the control area: 4 5 7-"The space will be ignored, printed or 4,5,7
Example 2
scanf ("%d%c%d", &a,&b,&c);
If you enter:4c7-> in the control area, print is 4,c,7
However, if you appear in front of the character < space >< comma >< carriage return, the structure is wrong,
If you enter in the control area: 4 C7->&a will take away 4,&b will take away < space >,&c will take C, and then print it in ASCII code
This is an easy mistake to make (because < spaces > and < Enter >< comma > are characters)
The buffer is where the input is waiting,
C Language-scanf function