如何区分EOF字符和文件的实际结尾? [英] How do I distinguish between an EOF character, and the actual end of file?

查看:109
本文介绍了如何区分EOF字符和文件的实际结尾?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在读取文件时,我知道提供的最后一个字符是 EOF 。现在,当我在该文件中使用 EOF 字符时,会发生什么情况?

When reading a file, I understand the last character provided is an EOF. Now, what happens, when I have an EOF character in that file?

如何区分实的文件末尾,以及 EOF 字符?

How do I distinguish between the "real" end of a file, and the EOF character?

推荐答案

我决定将评论移至答案。

I decided to move my comments to an answer.

您的文件中没有字符,因为没有事情。底层的文件系统知道一个文件中有多少字节。

You can't have an "EOF character" in your file because there is no such thing. The underlying filesystem knows how many bytes are in a file; it doesn't rely on the contents of the file to know where the end is.

您正在使用的C函数返回 EOF code>(-1),但不是从文件中读取的。这就是该功能告诉您即将结束的方式。而且因为-1在任何字符集中都不是有效字符,所以不会造成混淆。

The C functions you're using return EOF (-1) but that wasn't read from the file. It's just the way the function tells you that you're reached the end. And because -1 isn't a valid character in any character set, there's no confusion.

这篇关于如何区分EOF字符和文件的实际结尾?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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