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
17
votes
4 answers

Python binary EOF

I want to read through a binary file. Googling "python binary eof" led me here. Now, the questions: Why does the container (x in the SO answer) contain not a single (current) byte but a whole bunch of them? What am I doing wrong? If it should be so…
mekkanizer
  • 722
  • 2
  • 9
  • 28
17
votes
4 answers

fseek on a position beyond EOF does not trigger EOF using feof, how come?

I'm reading data from a file to memory that is opened with: FILE *f = fopen(path, "rb"); Before I start copying bytes from the file I seek to a start position using: /** …
rzetterberg
  • 10,146
  • 4
  • 44
  • 54
16
votes
3 answers

Go: unexpected EOF while reading from a socket

I have the following simple golang program to download Google's privacy policy. Unfortunately it always crashes with the error unexpected EOF after reading 6861 bytes, even though the document is much longer. Why? package main import "net" import…
aaronsw
  • 4,455
  • 5
  • 31
  • 27
16
votes
2 answers

Golang unexpected EOF

Here's my code, I'm new to Go. I tried googling the issue, but I can't quite put my finger on it. I think it has something to do with the Read() method. package main import ( ... ) type compressor struct { content []byte } func (r…
Dylan
  • 625
  • 1
  • 9
  • 21
15
votes
2 answers

tar.extractall() does not recognize unexpected EOF

The Python tarfile library does not detect a broken tar. user@host$ wc -c good.tar 143360 good.tar user@host$ head -c 130000 good.tar > cut.tar user@host$ tar -tf cut.tar ... tar: Unexpected EOF in archive tar: Error is not recoverable: exiting…
guettli
  • 25,042
  • 81
  • 346
  • 663
15
votes
1 answer

Bash: warning: here-document at line delimited by end-of-file (wanted `EOF')

The following function in bash comes up with the error mentioned in the title. The error usually appears when the final EOF is not at the beginning of the line. EOF is at the beginning so I can't see what is wrong. Further up in the script (not…
slooow
  • 329
  • 1
  • 3
  • 10
14
votes
11 answers

How to signify no more input for string ss in the loop while (cin >> ss)

I used "cin" to read words from input stream, which like int main( ){ string word; while (cin >> word){ //do sth on the input word } // perform some other operations } The code structure is something like the above one.…
user630983
  • 947
  • 2
  • 9
  • 16
14
votes
1 answer

Node.js multiline input

I'd like to prompt the user for input, let the user enter multiple lines of text, hitting enter between each line, then terminate the input by pressing CTRL+D or some such thing. With "keypress", I can catch the EOF, but I would have to handle all…
Rich Remer
  • 2,123
  • 1
  • 21
  • 22
14
votes
11 answers

How to detect EOF in awk?

Is there a way to determine whether the current line is the last line of the input stream?
user3562
  • 587
  • 3
  • 6
  • 11
14
votes
5 answers

How can I signal EOF to close stdin under the Git Bash terminal on Windows? Ctrl-D didn't work

I'm writing a command line tool. One of the things this tool can do (certainly not uniquely) is read it's input from stdin. I was testing this interactively (by typing input, rather than cat'ing a file in) when I noticed that I have no clue how to…
burfl
  • 2,138
  • 2
  • 20
  • 18
13
votes
2 answers

Is it possible to distinguish the error returned by fgets

Upon looking at the ISO C11 standard for fgets §7.21.7.2, 3, the return value is stated regarding the synopsis code: #include char *fgets(char* restrict s, int n, FILE* restrict stream); The fgets function returns s if successful. If…
Miket25
  • 1,895
  • 3
  • 15
  • 29
13
votes
5 answers

bison end of file

If I forget to put an empty line at the end of any of my files my program gets a syntax error. The problem is my grammar expects a newline to end the current line. Since a newline doesn't exist bison generates a syntax error because it does not…
user34537
13
votes
3 answers

Why doesn't the EOF character work if put at the end of a line?

I'm learning C++ and trying to understand, Why doesn't the EOF character (Ctrl + Z on Windows) break the while loop if put at the end of a line? My code: int main() { char ch; while(cin >> ch) { cout << ch; …
Cutter
  • 1,673
  • 7
  • 27
  • 43
13
votes
2 answers

fgetc, checking EOF

In the book Linux System Programming I have read some like this: fgetc returns the character read as an unsigned char cast to an int or EOF on end of file or error. A common error using fgetc is: char c; if ((c = fgetc()) != EOF) {...} The right…
pproger
  • 347
  • 1
  • 2
  • 9
12
votes
8 answers

How to know if the next character is EOF in C++

I'm need to know if the next char in ifstream is the end of file. I'm trying to do this with .peek(): if (file.peek() == -1) and if (file.peek() == file.eof()) But neither works. There's a way to do this? Edit: What I'm trying to do is to add a…
Tae
  • 1,665
  • 5
  • 24
  • 45