增量文件指针 [英] Increment file pointer

查看:61
本文介绍了增量文件指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨伙计


我有一个指向文件的指针。如果我增加指针,它会指向哪里。

我在常见问题解答中找不到问题。


提前谢谢

Deepak garg

解决方案

deepak< de ********* @ rediffmail.com>潦草地写道:

嗨大家
我有一个指向文件的指针。如果我增加指针,它会指向哪里。
我在常见问题解答中找不到问题。




它是未定义的。


-

/ - Joona Palaste(pa*****@cc.helsinki.fi)------------ - 芬兰-------- \

\-- http://www.helsinki.fi/~palaste ---------------------规则! -------- /

真相就在那里,伙计!出路!

- Ashfield教授


deepak写道:

嗨伙计

我有一个指向文件的指针。如果我增加指针,它将指向何处。我在常见问题解答中找不到问题。




这是FAQ 4.4,它似乎不在网上版本中。在那个

答案中,Steve Summit说C中的指针算法总是

自动按照指向的对象的大小缩放,这是一个

非常好的方式。


很容易犯错误,认为所谓的文件指针

指向文件中的某个位置,这样增加它会使它指向下一个位置,但是这样的想法是有缺陷的。文件指针

指向FILE对象,它是FILE对象包含有关正在读取,写入或更新的流的信息

,例如(例如)a

当前位置指示器。


++ fp;通常是在寻找麻烦。我可以想一想它可能有用的情况,但它们并不常见。


递增fp的例子:


FILE OutputArray [12 + 1] = {0};

FILE * fp = NULL;


if(OK == OpenAllMyFiles( OutputArray,

sizeof OutputArray / sizeof OutputArray [0]) - 1)

{

for(fp = OutputArray; fp!= NULL; fp ++)

{

DoSomethingWith(data,fp);

}

}


-

Richard Heathfield: bi****@eton.powernet .co.uk

Usenet是一个奇怪的地方。 - Dennis M Ritchie,1999年7月29日。

C FAQ: http://www.eskimo.com/~scs/C-faq/top.html

K& R答案,C书等:< a rel =nofollowhref =http://users.powernet.co.uk/etontarget =_ blank> http://users.powernet.co.uk/eton


文章< 7c ************************** @ posting.google.com> ,
de*********@rediffmail.com (deepak)写道:

嗨伙计们

我有一个指向文件的指针。如果我增加指针,它会指向哪里。
我在常见问题解答中找不到问题。




过了文件末尾。


hi folks

I have a pointer to a file. If i increment the pointer, where will it point.
I could not find the problem in the FAQs.

Thanks in advance
Deepak garg

解决方案

deepak <de*********@rediffmail.com> scribbled the following:

hi folks I have a pointer to a file. If i increment the pointer, where will it point.
I could not find the problem in the FAQs.



It''s undefined.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"The truth is out there, man! Way out there!"
- Professor Ashfield


deepak wrote:

hi folks

I have a pointer to a file. If i increment the pointer, where will it
point. I could not find the problem in the FAQs.



It''s FAQ 4.4, which doesn''t appear to be in the online version. In that
answer, Steve Summit says that "pointer arithmetic in C is always
automatically scaled by the size of the objects pointed to", which is a
very good way to put it.

It is easy to make the mistake of thinking that a so-called "file pointer"
points to a position in the file, so that incrementing it would make it
point to the next position, but such thinking is flawed. A file pointer
points to a FILE object, and it is the FILE object contains information
about the stream being read, written or updated, such as (for example) a
current position indicator.

++fp; is normally asking for trouble. I can think of circumstances where it
might be useful, but they are not overly common.

Example of incrementing fp:

FILE OutputArray[12 + 1] = {0};
FILE *fp = NULL;

if(OK == OpenAllMyFiles(OutputArray,
sizeof OutputArray / sizeof OutputArray[0]) - 1)
{
for(fp = OutputArray; fp != NULL; fp++)
{
DoSomethingWith(data, fp);
}
}

--
Richard Heathfield : bi****@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton


In article <7c**************************@posting.google.com >,
de*********@rediffmail.com (deepak) wrote:

hi folks

I have a pointer to a file. If i increment the pointer, where will it point.
I could not find the problem in the FAQs.



Past the end of the file.


这篇关于增量文件指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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