scanf function
The scanf function is a standard library function in C language for reading data from standard input.
Usage
Syntax:
<code class="c">int scanf(const char *format, ...);</code>
Among them:
format
: Specify input data format. ...
: A variable number of parameters, variables representing input data. Function
The scanf function reads data from the standard input in the specified format and stores the read data in the corresponding variables. It reads input character by character until valid data is encountered or an end-of-file (EOF) or newline character is encountered.
Format specifier
The format parameter uses a format specifier to specify the type of data to be read. Common format specifiers include:
<code>%c:字符 %d:有符号十进制整数 %f:浮点数 %s:字符串</code>
Return
The scanf function returns the number of variables successfully read. If no variables could be read, 0 is returned.
Example
The following example demonstrates how to use the scanf function to read an integer and a floating point number:
<code class="c">int num; float value; scanf("%d %f", &num, &value); printf("整数:%d\n", num); printf("浮点数:%f\n", value);</code>
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!