如何检索文本文件中的行
我开始用 C 语言编程,在读取文本文件时遇到一些问题。让我解释一下。
我有一个文件文本,其组织方式如下:
Tony
12.23
John
09.45
Tayris
03.99
我想检索所有少于十的笔记并显示它们,但我不能......
有人可以帮助我吗?
多谢。
I started programing in language C, and I have some problems with reading text files. Let me explain.
I have one file text which is organized like this :
Tony
12.23
John
09.45
Tayris
03.99
I would like to retrieve all notes less than ten and display them, but I can't...
Does anybody could help me?
Thanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
C 提供了四个可用于从磁盘读取文件的函数:
fscanf()
面向字段的函数。
fgets()
面向行的函数。
fgetc()
面向字符的函数
fread()
面向块的函数。
请参阅本文了解更多信息。
C provides four functions that can be used to read files from disk:
fscanf()
field oriented function.
fgets()
line oriented function.
fgetc()
character oriented function
fread()
block oriented function.
See this article for more information.
查看
fgets
函数。它将返回直到(并包括)字符串字符的末尾(如果需要,您可以将其从目标字符串中删除)。http://people.cs.uchicago.edu/~iancooke/osstuff/ccc .html 提供了一个示例:
我想这应该足够了。
Check out the
fgets
function. It will return until (and including) the end of string character (you can strip it from the destination string if you want).http://people.cs.uchicago.edu/~iancooke/osstuff/ccc.html offers an example:
That should be enough I think.