如何在C编程语言中使用fscanf()函数读取输入?

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值