CR-NL,NL和ftell [英] CR-NL, NL and ftell

查看:221
本文介绍了CR-NL,NL和ftell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好


打开CR-NL文件时,ftell返回文件的长度,其中

CR-NL为两个字节,是吗应该这样做吗?


我正在比较两个文件大小,一个CR-NL和一个NL使用ftell获取

文件大小。欢迎任何其他建议。


谢谢

- Martin Johansen

解决方案

Martin Johansen写道:


你好

打开CR-NL文件时,ftell返回文件的长度和
CR-NL作为两个字节,它应该这样做吗?


否。返回文件长度不是ftell的工作。

我正在比较两个文件大小,一个CR-NL和一个NL使用ftell来获取
文件大小。欢迎提出任何其他建议。




文件大小是什么意思?文件占用的磁盘集群数量乘以集群大小?

while的字节数((ch = getc(fp))!= EOF){++ count;在二进制模式下打开文件

时会计算?还是文字模式?

文件占用的磁带块数量乘以磁带块大小?


直到C世界可以就文件大小达成一致意见为止意味着,

仍然没有标准的查找方式。


On Sun,2005年2月20日05:49:26 +0100 ,Martin Johansen

< mf ** @ online.no>写道:

当打开CR-NL文件时,ftell返回文件的长度,其中
CR-NL为两个字节,是否应该这样做?


我假设您首先寻找文件的末尾。


是的,它可以。


如果文件处于二进制模式,则是,它将报告文件中

字符的数量。这将是您使用getc()读取并计算它们(可能与磁盘上的

分配空间或其他任何内容不同)的字符数。如果它处于文本模式,那么关于ftell()的唯一保证就是它返回一个值,该值可以是后来被fseek()用来获得的
在相同的位置,该值可能没有

与文件大小的其他关系。

我正在比较两个文件大小,一个CR-NL和一个NL使用ftell来获取
文件大小。欢迎任何其他建议。




如果你真的想要文件大小,你将不得不使用操作系统

特定的功能(在许多系统,寻找stat()和fstat())。如果

你想知道可以从文件中读取的字符数

在文本模式下打开,唯一的方法是读取它并计算它们。你不能保证价值低于

以二进制模式打开它的价值。


Chris C


Chris Croughton写道:


On Sun,2005年2月20日05:49:26 +0100,Martin Johansen
< mf ** @ online.no>写道:

当打开CR-NL文件时,ftell返回文件的长度,其中
CR-NL为两个字节,是否应该这样做? / blockquote>

我假设您首先寻找文件的末尾。

是的,它可以。

如果文件是二进制模式,然后是,它将报告文件中
字符的数量。




"二进制流不需要有意义地支持fseek调用

值为SEEK_END。


Hello

When opening a CR-NL file, ftell returns the length of the file with the
CR-NL as two bytes, is it supposed to do so?

I am comparing two file-sizes, one CR-NL and one NL using ftell to get the
filesize. Any alternative suggestion is welcomed.

Thanks
- Martin Johansen

解决方案

Martin Johansen wrote:


Hello

When opening a CR-NL file, ftell returns the length of the file with the
CR-NL as two bytes, is it supposed to do so?
No. It is not ftell''s job to return the length of a file.
I am comparing two file-sizes, one CR-NL and one NL using ftell to get the
filesize. Any alternative suggestion is welcomed.



What do you mean by file size? The number of disk clusters occupied by
the file, multiplied by the cluster size? The number of bytes that
while((ch = getc(fp)) != EOF) { ++count; } would count when the file
is opened in binary mode? Or text mode? The number of tape blocks the
file occupies multiplied by the tape block size?

Until the C world can agree on what "file size" means, there will
continue to be no standard way of finding out.


On Sun, 20 Feb 2005 05:49:26 +0100, Martin Johansen
<mf**@online.no> wrote:

When opening a CR-NL file, ftell returns the length of the file with the
CR-NL as two bytes, is it supposed to do so?
I assume that you did a seek to the end of the file first.

Yes, it can.

If the file is in binary mode, then yes, it will report the number of
characters in the file. This will be the number of characters which you
can read using getc() and counting them (which may be different from the
allocated space on disk or whatever). If it''s in text mode, the only
thing guaranteed about ftell() is that it returns a value which can be
used later by fseek() to get to the same position, the value may have no
other relation to the size of the file at all.
I am comparing two file-sizes, one CR-NL and one NL using ftell to get the
filesize. Any alternative suggestion is welcomed.



If you actually want the filesize, you''ll have to use operating system
specific functions (on many systems, look for stat() and fstat()). If
you want to know the number of characters which can be read from a file
opened in text mode, the only way is to read it and count them. You
can''t even guarantee that the value will be less than that returned by
opening it in binary mode.

Chris C


Chris Croughton wrote:


On Sun, 20 Feb 2005 05:49:26 +0100, Martin Johansen
<mf**@online.no> wrote:

When opening a CR-NL file, ftell returns the length of the file with the
CR-NL as two bytes, is it supposed to do so?



I assume that you did a seek to the end of the file first.

Yes, it can.

If the file is in binary mode, then yes, it will report the number of
characters in the file.



"A binary stream need not meaningfully support fseek calls with a
whence value of SEEK_END."


这篇关于CR-NL,NL和ftell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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