0. The pits that I actually encountered
If you use a standard keyboard with a Mac, you cannot enter with the scanf on the keypad, or the system will not be well recognized.
1. Basic use of scanf function
1: //define a variable to hold the integer entered by the user
2: int number;
3:
4: //The SCANF function accepts only the address of the variable
5: //The scanf function is a blocking function that waits for user input
6: //When user input is complete, the value entered by the user will be assigned to the number variable
7: //function call complete
8: scanf ("%d", &number);
2. Other usage and attention points of scanf
1: /* 1. Enter characters
2: char Myc;
3:
4: scanf ("%c", &MYC);
5:
6: printf ("Input character is%c\n", MYC);
7: * /
8:
9: / * 2. Enter multiple values at once, separated by some symbols
Ten: int num1, num2;
11:
: scanf ("%d#%d", &num1, &num2);
13:
: printf ("num1=%d, num2=%d\n", NUM1, num2);
: * /
16:
+ / *
3. If the scanf parameter is separated by a space, the actual input can be delimited by a space, tab, carriage return
: int num1, num2;
: scanf ("%d%d", &NUM1, &num2);
: printf ("num1=%d, num2=%d\n", NUM1, num2);
: * /
23:
:/ *
4.SCANF : cannot write \ n
: int A;
: scanf ("%d\n", &a);//Wrong wording
: printf ("A's value is%d\n", a);
: * /
Dark Horse programmer--"Dark Horse video note" The use of the scanf function of C language Foundation