stdin中的文件结尾 [英] End of File in stdin

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

问题描述

有关此问题的问题已在此处
文件结尾(EOF )在C
中,但仍然不能完全解决我的问题。

A question about this has been asked here End of File (EOF) in C but it still doesn't completely solve my problem.

EOF 在任何不是 stdin 的数据流中对我来说都是有意义的,例如,如果我有一些 data.txt 文件, fgetc()将读取所有字符并到达文件末尾,并返回 -1

EOF makes sense to me in any datastream which is not stdin, for example if I have some data.txt file, fgetc() will read all the chars and come to the end of file and return -1.

我不理解的是 stdin 中的 EOF 的概念。如果我使用 getchar(),它将等待我输入内容,因此,如果没有写完文件末尾( EOF )是否不会自动返回?

What I don't understand is the concept of EOF in stdin. If I use getchar(), it will wait for me to enter something, so if there is NOTHING written, End of File, (EOF) is not returned automatically?

那么只有用户可以在其中调用 EOF 吗?通过按 Ctrl + Z stdin 吗?
如果是这样, stdin 中的 EOF 有什么用途?我猜它告诉程序继续读取,直到用户调用文件结尾?

So is it that only the user can invoke EOF in stdin by pressing Ctrl+Z? If so then what are some of the uses of EOF in stdin? I guess it tells the program to continue reading until the user invokes end of file? is this it?

谢谢

推荐答案


因此,如果没有写东西,文件尾(EOF)是否不会自动返回?

so if there is NOTHING written, End of File, (EOF) is not returned automatically?

不是,不是。它应该由用户发送。

No, it's not. It should be sent by the user.


是否只有用户可以调用 EOF Ctrl + Z stdin 中的$ c>?

So is it that only the user can invoke EOF in stdin by pressing Ctrl+Z?

是的,您可以为 EOF 指标> stdin ,您可以在控制台中输入特殊的组合键,对于 Ctrl + D 的Linux控制台,对于Windows的 Ctrl + Z

Yes, you can set the EOF indicator for stdin with a special key combination you can input in the console, for linux console that is Ctrl+D and for windows it's Ctrl+Z.


如果是,<$ c的用途是什么 stdin 中的$ c> EOF ?我猜它告诉程序继续读取,直到用户用户调用文件末尾为止?

If so then what are some of the uses of EOF in stdin? I guess it tells the program to continue reading until the user user invokes end of file? is this it?

使用它取决于您是否指示用户输入 EOF 是否显式,例如,我认为 python 控制台会告诉您类似的信息按Ctrl + D或键入quit()退出

The use of it depends on whether you instruct the user to input the EOF explicitly or not, for example, I think python console will tell you something like Press Ctrl+D or type quit() to exit.

EOF 不一定是 -1 是一个宏,您应该始终使用它来测试 EOF 指标。更重要的是 EOF 不是字符,它是一个特殊的值,它表示 E nd O f F ile指示器已设置。

And EOF is not necessarily -1 it's a macro and you should always use it to test for the EOF indicator. And more importantly EOF is not a character, it's a special value that indicates that the End Of File indicator is set.

此外, getchar()等效于 fgetc(stdin)

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

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