C programming language libraries provide some standard functions which can be used in different platforms like Linux and Windows. In this tutorial, we will learn how to use fscan()
function, return values and parameters with examples.
C编程语言库提供了一些标准功能,可以在诸如Linux和Windows等不同平台上使用。 在本教程中,我们将学习如何使用fscan()
函数,返回值和参数以及示例。
声明和参数 (Declaration and Parameters)
fscanf()
function will accept a file stream in FILE
type and format specifiers as char
type. In this case, format specifiers are important because the given file will be read in this format like "%s %s %s"
which means 3 strings with separated with spaces.
fscanf()
函数将接受FILE
类型和格式说明符作为char
类型的文件流。 在这种情况下,格式说明符很重要,因为给定文件将以"%s %s %s"
类的格式读取,这意味着3个字符串之间用空格分隔。
int fscanf(FILE *stream, const char *format, ...)
返回值 (Return Value)
fscanf
functions will return data with pointers provided as parameter. But as a function, it will also return the function operational status as int
. If operations are successfully completed it will return 1
as an integer.
fscanf
函数将使用指针作为参数返回数据。 但是作为函数,它也将返回函数操作状态为int
。 如果操作成功完成,它将返回1
作为整数。
阅读范例 (Read Example)
We will start with a simple example where we will read data from the file named test.txt
with fscanf()
function in the %s %s %s
format.
我们将从一个简单的示例开始,我们将使用fscanf()
函数以%s %s %s
格式从名为test.txt
的文件中读取数据。
Our data file will be named test