Home >Backend Development >C#.Net Tutorial >What does scanf mean in C language?
The scanf function is used to read data from standard input. It specifies the data type and format through a format string and returns the number of items read.
The meaning of scanf
scanf is used in C language to read from standard input (usually the keyboard) function of the data. The "scan" in its name means scan input and "f" means format.
Function prototype
<code class="c">int scanf(const char *format_string, ...);</code>
Parameters
format_string
: a format string, Specifies how the input is interpreted. ...
: An optional list of variables to receive the read data. How it works
scanf uses format_string
as a template to guide input interpretation. format_string
Contains format specifiers, each format specifier corresponding to a data type to be read (for example, %d
represents an integer, %f
represents a floating point number).
scanf scans the input characters one by one and converts them to the corresponding data type according to the format specifier. scanf reports an error if the input does not match the format specifier.
Return value
scanf returns an integer indicating the number of successfully read data items. If an error occurs or End of Input (EOF) is reached, EOF
is returned.
Example
The following code uses scanf to read an integer and a floating point number from standard input:
<code class="c">int num; float real; scanf("%d %f", &num, &real);</code>
Note
%*[whitespace]
. (where *
means read but discard input) The above is the detailed content of What does scanf mean in C language?. For more information, please follow other related articles on the PHP Chinese website!