免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12345678
最近访问板块 发新帖
楼主: zhjufe
打印 上一主题 下一主题

请问:怎么从某一确定的行开始读文件? [复制链接]

论坛徽章:
0
71 [报告]
发表于 2007-04-23 15:46 |只看该作者
一个看似简单的问题,原来还有那么多学问。。。。。。这里让我知道了一些我原来没有注意的东西,比如read不保险~
继续关注。

论坛徽章:
0
72 [报告]
发表于 2007-09-19 17:15 |只看该作者
Mark

论坛徽章:
1
双子座
日期:2015-01-04 14:25:06
73 [报告]
发表于 2008-03-16 14:52 |只看该作者
原帖由 flw 于 2007-4-7 17:23 发表

你看的是哪一版?
我这里有一份电子的,我看了一下,第 4.2 节讲的是 stat fstat 和 lstat 啊。没有说 read。
考虑到你有可能是 4.20 节的手误,我还特意看了一下,讲的是 mkdir。

《unix 高级环境编程》14.8
14.8. readn and writen Functions
Pipes, FIFOs, and some devices, notably terminals, networks, and STREAMS devices, have the following two properties.

A read operation may return less than asked for, even though we have not encountered the end of file. This is not an error, and we should simply continue reading from the device.

A write operation can also return less than we specified. This may be caused by flow control constraints by downstream modules, for example. Again, it's not an error, and we should continue writing the remainder of the data. (Normally, this short return from a write occurs only with a nonblocking descriptor or if a signal is caught.)

We'll never see this happen when reading or writing a disk file, except when the file system runs out of space or we hit our quota limit and we can't write all that we requested.

论坛徽章:
1
双子座
日期:2015-01-04 14:25:06
74 [报告]
发表于 2008-03-16 14:54 |只看该作者
原帖由 flw 于 2007-4-7 17:23 发表

你看的是哪一版?
我这里有一份电子的,我看了一下,第 4.2 节讲的是 stat fstat 和 lstat 啊。没有说 read。
考虑到你有可能是 4.20 节的手误,我还特意看了一下,讲的是 mkdir。

《unix 高级环境编程2》14.8
14.8. readn and writen Functions
Pipes, FIFOs, and some devices, notably terminals, networks, and STREAMS devices, have the following two properties.

A read operation may return less than asked for, even though we have not encountered the end of file. This is not an error, and we should simply continue reading from the device.

A write operation can also return less than we specified. This may be caused by flow control constraints by downstream modules, for example. Again, it's not an error, and we should continue writing the remainder of the data. (Normally, this short return from a write occurs only with a nonblocking descriptor or if a signal is caught.)

We'll never see this happen when reading or writing a disk file, except when the file system runs out of space or we hit our quota limit and we can't write all that we requested.

论坛徽章:
36
IT运维版块每日发帖之星
日期:2016-04-10 06:20:00IT运维版块每日发帖之星
日期:2016-04-16 06:20:0015-16赛季CBA联赛之广东
日期:2016-04-16 19:59:32IT运维版块每日发帖之星
日期:2016-04-18 06:20:00IT运维版块每日发帖之星
日期:2016-04-19 06:20:00每日论坛发贴之星
日期:2016-04-19 06:20:00IT运维版块每日发帖之星
日期:2016-04-25 06:20:00IT运维版块每日发帖之星
日期:2016-05-06 06:20:00IT运维版块每日发帖之星
日期:2016-05-08 06:20:00IT运维版块每日发帖之星
日期:2016-05-13 06:20:00IT运维版块每日发帖之星
日期:2016-05-28 06:20:00每日论坛发贴之星
日期:2016-05-28 06:20:00
75 [报告]
发表于 2008-03-16 19:43 |只看该作者
默默的学习,然后赞一把

论坛徽章:
0
76 [报告]
发表于 2008-03-16 21:05 |只看该作者
考虑兼容性和可移植性的话,还是应该使用stdio来实现。

还是用fgets吧!

论坛徽章:
36
IT运维版块每日发帖之星
日期:2016-04-10 06:20:00IT运维版块每日发帖之星
日期:2016-04-16 06:20:0015-16赛季CBA联赛之广东
日期:2016-04-16 19:59:32IT运维版块每日发帖之星
日期:2016-04-18 06:20:00IT运维版块每日发帖之星
日期:2016-04-19 06:20:00每日论坛发贴之星
日期:2016-04-19 06:20:00IT运维版块每日发帖之星
日期:2016-04-25 06:20:00IT运维版块每日发帖之星
日期:2016-05-06 06:20:00IT运维版块每日发帖之星
日期:2016-05-08 06:20:00IT运维版块每日发帖之星
日期:2016-05-13 06:20:00IT运维版块每日发帖之星
日期:2016-05-28 06:20:00每日论坛发贴之星
日期:2016-05-28 06:20:00
77 [报告]
发表于 2008-03-17 09:47 |只看该作者
从以上讨论来看,是不是每次只取一个字符,然后判断,是最有效的一种方法呢?

论坛徽章:
0
78 [报告]
发表于 2008-03-17 15:30 |只看该作者
星辰技术社区:www.netcsharp.cn,您将获得最新,最全的.NET技术信息.您将时刻掌握最前沿的.NET技术动向~~~欢迎您的加入

论坛徽章:
0
79 [报告]
发表于 2008-03-18 17:25 |只看该作者
原帖由 star65225692 于 2008-3-17 15:30 发表
星辰技术社区:www.netcsharp.cn,您将获得最新,最全的.NET技术信息.您将时刻掌握最前沿的.NET技术动向~~~欢迎您的加入


这个时候出现一则广告 有点搞笑了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP