Home >Backend Development >C#.Net Tutorial >The role of scanfs in c language
The scanfs function is used in C language to read formatted data from standard input and store the read data in the specified variable. It reads data according to the format specifier (such as %d, %f) specified by the format parameter and stores the data in the variable address specified in the ... parameter. The scanfs function returns the number of data items read successfully, or -1 if the read fails.
What is the role of scanfs in C language
?
scanfs is a standard input function in C language, used to read formatted data from standard input.
Function:
How to use:
The syntax of the scanfs function is as follows:
<code class="c">int scanfs(const char *format, ...);</code>
Among them:
format
: The format specifier string to read data from the input. ...
: Address list of variables to store read data. Format specifier:
The format specifier is a sequence of characters that specifies the type and format of the data to be read. Common format specifiers include:
%d
: Read integer %f
: Read floating point number %c
: Read character %s
: Read string Example:
Read an integer and store it in the variable num
:
<code class="c">int num; scanfs("%d", &num);</code>
Read a floating point number and store it in the variable pi
:
<code class="c">float pi; scanfs("%f", &pi);</code>
Note:
&
. The above is the detailed content of The role of scanfs in c language. For more information, please follow other related articles on the PHP Chinese website!