C-如何从文件中读取某些行? (不是所有行或整个文件,而是某些行) [英] C - How to read certain lines from a file? ( Not all lines or entire file but just certain lines)

查看:52
本文介绍了C-如何从文件中读取某些行? (不是所有行或整个文件,而是某些行)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图寻找类似的问题,这些问题可以找到我的问题的答案,但我似乎找不到.有人可以告诉我,有什么方法可以读取.txt文件中的某些行.例如,我想从文本文件中读取第2、3、5行.

I tried looking for similar questions that could find an answer to my question but i couldn't seem to find it. Could someone please tell me is there any way to read certain lines from the .txt file. For example i would like to read lines 2,3,5 from the text file.

文本文件示例:

1255466889436     //Line 1 - I want to read this line
5489784642165     //Line 2
4984651425165     //Line 3 - I want to read this line
4968164816514     //Line 4
4161654168468     //Line 5 - I want to read this line

如果somone可以显示示例代码,导致即时通讯真正陷入困境,那将是一个很好的选择.

It would be nice if somone could show example code cause im really stumped at the moment.

推荐答案

读取所有行,丢弃不需要的行.

Read all lines, discard the ones you don't need.

您可以查找文件中的任何偏移量,但是哪一行偏移量为5000?这取决于前5000个字符中有多少个换行符.而且,除非您检查所有字符,否则您将不知道.

You can seek to any offset in a file, but which line is offset 5000? That depends on how many newline characters there were in the previous 5000 characters. And unless you check all characters, you don't know.

这篇关于C-如何从文件中读取某些行? (不是所有行或整个文件,而是某些行)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆