Scanf () Function Doubt (Part) 1. The preambular SCANF () function is the second function encountered in all C language learners in learning the C language (the first function is Printf (), Brian W.kerninghan & Dennis M.Ritchie's "Hello, World" program is basically all the first example of all C language learners), so the scanf () function should be a function that C learners can use, but there are many beginners to this. Function is not well used, using the scanf () function in actual programming, leading to the program to generate a certain error that does not work properly, so that the "scanf () function has bug", "scanf () function is useless", etc. Error view. This article combines the author's problems in programming practice and the forum, but the author is limited (rookie-level), it is inevitable that there is a fallacy, but also hope that one will be directed. (Email: knocker.k@126.com) Only, the next two two articles describe the usage of the scanf () function in the C language, focusing on using common errors and countermeasures that occur during the SCANF () function. Of course, some of the solutions in the text can be better resolved with other functions and methods, but this article only discusses the scanf () function itself. The upper article, the configuration of the SCANF () function control string is described in detail. The next article, introduces the common errors and countermeasures techniques that appear in the SCANF () function control string using the actual routine. Second, the SCANF () function control string function name: scanf function: Perform a formatting input: int Scanf (char * format [, argument, ...]); scanf () function is a general terminal formatting input function It reads the input information from the standard input device (keyboard). You can read any natural type data and automatically convert the numerical value into an appropriate machine format. Its call format is: scanf ("
Non-blank characters; (a) formatted explanatory format character Description% A Read a floating point value (only C99 effective)% a to read a character% D read into a decimal integer% i read into decimal, octal, Hexadecimal integer% o Reads eight-input integer% x Read the hexadecimal integer% x That is read into a character% s Read a string% f Reading a floating point% f The same upper% E E The same upper% g is the same, the upper% g is read into a pointer% u, read into a non-symbolic decimal integer% N to this class-entered value to the equivalent character number% [] Scan Character Set %% Read% Symbol Additional Format Description Character Table modifier Description L / L length modifier input "long" data H length modifier input "short" data W integer specified input data The width of the input data * the asterisk is empty to read a data HH, LL is the same on H, L but only Valid of C99. (B) Blank character blank characters will enable the scanf () function to ignore one or more blank characters in the input in the read operation, and the blank character can be Space, Tab, Newline, and the like until the first non-empty compilation occurs. (C) Non-blank characters A non-empty chain makes the scanf () function to remove the same characters as this non-blank characters during reading. Note: SCANF () control string knowledge will introduce here (it should be completely ^ _ ^), if there is any missing next time. Next, the actual routine will be set forth one by one. Third, the use example of the SCANF () function 1. # include "stdio.h" int main (void) {Int A, B, C; scanf ("% D % D% D ", & A, & B, & C); Printf ("% D,% D,% D / N ", A, B, C); RETURN 0;} When running as follows: 3 □ 4 □ 5 ↙ (Value of A, B, C) 3, 4, 5 (the value of the A, B, C) (value of Printf) (1) & a, & b, & c & is address operators, respectively The memory address of these three variables. (2) "% D% D% D" is to enter three values in the decay format. When entering, one or more spaces, tab keys, and auto keys can be separated by one or more spaces.