Home > Backend Development > C#.Net Tutorial > What does scanf mean in C language?

What does scanf mean in C language?

下次还敢
Release: 2024-05-09 11:42:17
Original
700 people have browsed it

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>
Copy after login

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>
Copy after login

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template