Questions tagged [eof]

End of file (commonly abbreviated EOF) is a condition in a computer operating system where no more data can be read from a data source.

From Wikipedia:

End of file (commonly abbreviated EOF) is a condition in a computer operating system where no more data can be read from a data source. The data source is usually called a file or stream.

EOF is also a macro defined in the <stdio.h> header of the C standard library. This macro:

expands to an integer constant expression, with type int and a negative value, that is returned by several functions to indicate end-of-file, that is, no more input from a stream;

For more information:

1831 questions
25
votes
4 answers

eof() bad practice?

Possible Duplicate: Why is iostream::eof inside a loop condition considered wrong? So I've been using the eof() function in a lot of my programs that require file input, and my professor said that it is fine to use but a few people on SO have…
Sam
  • 2,309
  • 9
  • 38
  • 53
25
votes
4 answers

Linux - check if there is an empty line at the end of a file

NOTE: this question used to be worded differently, using “with/out newline” instead of “with/out empty line” I have two files, one with an empty line and one without: File: text_without_empty_line $root@kali:/home#cat text_without_empty_line This is…
Black
  • 18,150
  • 39
  • 158
  • 271
25
votes
4 answers

End of File in stdin

A question about this has been asked here End of File (EOF) in C but it still doesn't completely solve my problem. 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…
Mcs
  • 534
  • 1
  • 5
  • 14
25
votes
2 answers

git: new blank line at EOF

So I run git diff --check before add-ing files and commit-ing them, and on two specific files I get path/filename:linenumber: new blank line at EOF. If I delete the last empty line in those files, I don't get any messages, but I think it is good…
Maxim Chetrusca
  • 3,262
  • 1
  • 32
  • 28
25
votes
5 answers

What really is EOF for binary files? Condition? Character?

I have managed this far with the knowledge that EOF is a special character inserted automatically at the end of a text file to indicate its end. But I now feel the need for some more clarification on this. I checked on Google and the Wikipedia page…
Thokchom
  • 1,602
  • 3
  • 17
  • 32
23
votes
1 answer

Sublime Text 3 - ensure _only_ one trailing newline at end of file

I'm using Sublime Text 3 and want to ensure I get only a single new line at the end of a file on save. At the moment, 90% of the time my whitespace works perfectly, using: "ensure_newline_at_eof_on_save":…
SRack
  • 11,495
  • 5
  • 47
  • 60
22
votes
3 answers

Why is failbit set when eof is found on read?

I've read that predates . Ignoring the fact that exceptions on fstream aren't very informative, I have the following question: It's possible to enable exceptions on file streams using the exceptions() method. ifstream…
ceztko
  • 14,736
  • 5
  • 58
  • 73
20
votes
2 answers

Visual Studio - blank line at the end of each new file

Why does VS add a blank line at the end of each new file I create? I use VS to create .NET projects (not C++ or something). Is there any special reason? Historical compatibility with compilers and parsers? Can I disable this??
Andrei Rînea
  • 20,288
  • 17
  • 117
  • 166
20
votes
4 answers

Prevent FIFO from closing / reuse closed FIFO

Consider the following scenario: a FIFO named test is created. In one terminal window (A) I run cat test. It is now possible to write in window B and get the output in window A. It is also possible to terminate the…
Shump
  • 454
  • 1
  • 4
  • 11
20
votes
5 answers

End of nonblocking file

How is end of file detected for a file in nonblocking mode?
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
19
votes
1 answer

How to instruct clang-format to add EOL-character at file's end?

Maybe I miss something, but still didn't find such a setting. Formally speaking clang-format doesn't produce proper UNIX text files, since last lines always lack EOL-character.
ababo
  • 1,490
  • 1
  • 10
  • 24
18
votes
3 answers

Why do I have to type ctrl-d twice?

For my own amusement, I've cooked up a python script that allows me to use python for bash one-liners; Supply a python generator expression; and the script iterates over it. Here's the script: DEFAULT_MODULES = ['os', 're', 'sys'] _g = {} for m in…
SingleNegationElimination
  • 151,563
  • 33
  • 264
  • 304
18
votes
2 answers

In python, how to check the end of standard input streams (sys.stdin) and do something special on that

I want to do something like: for line in sys.stdin: do_something() if is **END OF StdIn**: do_something_special() After a few tries, for now I am doing this: while True: try: line = sys.stdin.next() print line, …
YaOzI
  • 16,128
  • 9
  • 76
  • 72
18
votes
3 answers

Why do I need to type Ctrl-D twice to mark end-of-file?

char **query; query = (char**) malloc ( sizeof(char*) ); int f=0; int i=0,j=0,c; while((c=getchar())!=EOF) { if(!isalpha(c)) continue; if(f==1) query=(char**) realloc(query,(i+1)*sizeof(char*)); …
mualloc
  • 495
  • 9
  • 24
17
votes
4 answers

Fundamentals of iostream and read/writeObject calls

I am designing a java server to respond to multiple client requests. So the design basically has a server socket, accepts a client socket, creates a inputObjectStream and a outputObjectStream from the client input/outputStream. I then use…
Siddharth
  • 9,349
  • 16
  • 86
  • 148