To put it simply:
The C language itself does not directly provide input and output statements, and the input and output are provided by functions:
Getchar () // input a character constant from the keyboard. This constant is the value returned by the function;
Putchar () // output a character constant in the variable;
Scanf () // input various types of data from the keyboard and store the data in program variables;
Printf () // format all types of data on the keyboard to control the output;
Gets () // read a String constant and put it in the array of the program;
Puts () // Output A String constant in the array variable with the carriage return '\ n ';
Sscanf () // extract various types of data from a string;
Sprintf () // write various types of data into strings;
I. printf () functions // fprintf, sprintf and printf have the same usage. In fact, I personally think:
Fprintf (stdout, "", &) = printf ("",&);
Printf () is a formatting output function, which is generally used to output data to a standard output device in the specified format.
Information. This function is often used in programming. The call format of the printf () function is:
Printf ("<formatted string>", <parameter table> );
The formatted string consists of two parts: one part is a normal character, which will be based on the original
Sample output. The other part is to format the specified character, starting with "%", followed by one or more specified characters,
Used to determine the output content format.
A parameter table is a series of parameters that need to be output. The number of parameters must be the same as that described in the formatted string.
There are as many parameters as they are. "," are used to separate them and the order is one-to-one. Otherwise, you may want
Error.
II. the scanf () function // is similar to printf. The format of fscanf, sscanf, and scanf is basically the same.
The scanf () function is a formatting input function that reads input information from the standard input device (keyboard.
The call format is:
Scanf ("<formatted string>", <Address Table> );
The formatted string contains the following three types of characters;
1. format specifiers: The format specifiers are basically the same as those in the printf () function.
2. Blank characters: the blank characters will slightly remove one or more
White space characters.
3. Non-blank characters: A non-blank character will remove the scanf () function from reading
Characters with the same white space characters.
The address table is the address of all variables to be read, not the variable itself. This is the same as the printf () function.
It is completely different. Pay special attention to it. The addresses of each variable are separated by commas.
3. Puts () and gets () Functions
1. puts () function
The puts () function is used to write a string to the standard output device (screen) and wrap the line. The call format is:
Puts (s );
S is a string variable (string array name or string pointer ).
The puts () function works the same way as printf ("% s \ n", s.
2. gets () function
The gets () function is used to read a string from the standard input device (keyboard) until the carriage return ends, but the carriage return
Does not belong to this string. The call format is:
Gets (s );
S is a string variable (string array name or string pointer ).
The gets (s) function is similar to scanf ("% s", & s), but not exactly the same. Use scanf ("% s", & s)
A problem occurs when the function inputs a string, that is, if a space is entered, the input string ends,
The character after the space is processed as the next input, but the gets () function will receive the entire input character
String until press Enter.
--