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
672
votes
5 answers

Why is “while( !feof(file) )” always wrong?

What is wrong with using feof() to control a read loop? For example: #include #include int main(int argc, char **argv) { char *path = "stdin"; FILE *fp = argc > 1 ? fopen(path=argv[1], "r") : stdin; if( fp == NULL…
William Pursell
  • 204,365
  • 48
  • 270
  • 300
349
votes
9 answers

Why is it recommended to have empty line in the end of a source file?

Some code style tools recommend this and I remember seeing some unix command line tools warning about missing empty line. What is the reasoning for having an extra empty line?
Petteri H
  • 11,779
  • 12
  • 64
  • 94
157
votes
8 answers

What is the perfect counterpart in Python for "while not EOF"

To read some text file, in C or Pascal, I always use the following snippets to read the data until EOF: while not eof do begin readline(a); do_something; end; Thus, I wonder how can I do this simple and fast in Python?
Allen Koo
  • 1,996
  • 3
  • 14
  • 15
149
votes
9 answers

read.csv warning 'EOF within quoted string' prevents complete reading of file

I have a CSV file (24.1 MB) that I cannot fully read into my R session. When I open the file in a spreadsheet program I can see 112,544 rows. When I read it into R with read.csv I only get 56,952 rows and this warning: cit <-…
Ben
  • 41,615
  • 18
  • 132
  • 227
96
votes
9 answers

Why does the IPython REPL tell me "SyntaxError: unexpected EOF while parsing" as I input the code?

I'm getting an error while running this part of the code. I tried some of the existing solutions, but none of them helped. elec_and_weather = pd.read_csv(r'C:\HOUR.csv', parse_dates=True,index_col=0) # Add historic DEMAND to each X vector for i in…
Akash Joshi
  • 1,099
  • 1
  • 9
  • 13
95
votes
22 answers

How to find out whether a file is at its `eof`?

fp = open("a.txt") #do many things with fp c = fp.read() if c is None: print 'fp is at the eof' Besides the above method, any other way to find out whether is fp is already at the eof?
Alcott
  • 17,905
  • 32
  • 116
  • 173
85
votes
11 answers

Python unexpected EOF while parsing

Here's my python code. Could someone show me what's wrong with it. while 1: date=input("Example: March 21 | What is the date? ") if date=="June 21": sd="23.5° North Latitude" if date=="March 21" | date=="September 21": …
Web_Designer
  • 72,308
  • 93
  • 206
  • 262
83
votes
3 answers

End of File (EOF) in C

I am currently reading the book C Programming Language by Ritchie & Kernighan. And I am pretty confused about the usage of EOF in the getchar() function. First, I want to know why the value of EOF is -1 and why the value of getchar()!=EOF is 0.…
newbie
  • 14,582
  • 31
  • 104
  • 146
70
votes
4 answers

How to read user input until EOF?

My current code reads user input until line-break. But I am trying to change that to a format, where the user can write input until strg+d to end his input. I currently do it like this: input = raw_input ("Input: ") But how can I change that to an…
Saphire
  • 1,812
  • 1
  • 18
  • 34
69
votes
15 answers

Go failing - expected 'package', found 'EOF'

I've been having a hard time trying to execute a simple golang program in a virtual machine powered by vagrant. These are the relevant fields of my go…
ThisIsErico
  • 1,885
  • 2
  • 19
  • 24
66
votes
11 answers

Representing EOF in C code?

The newline character is represented by "\n" in C code. Is there an equivalent for the end-of-file (EOF) character?
static_rtti
  • 53,760
  • 47
  • 136
  • 192
65
votes
10 answers

"/usr/bin/python^M: bad interpreter"

Cannot figure out, where to change EOF in PyCharm. My scripts start with : #!/usr/bin/python # -*- coding: utf-8 -*- It outputs something like this when I try to run it like an executable (chmode +x) : -bash: ./main.py: /usr/bin/python^M: bad…
woozly
  • 1,363
  • 1
  • 14
  • 24
60
votes
8 answers

How to use `while read` (Bash) to read the last line in a file if there’s no newline at the end of the file?

Let’s say I have the following Bash script: while read SCRIPT_SOURCE_LINE; do echo "$SCRIPT_SOURCE_LINE" done I noticed that for files without a newline at the end, this will effectively skip the last line. I’ve searched around for a solution and…
Mathias Bynens
  • 144,855
  • 52
  • 216
  • 248
59
votes
5 answers

How to simulate an EOF?

I am currently reading K&R's book and typing in the examples from the first section, and there are a couple of examples such as this: while((c = getchar()) != EOF) { //do something } I am testing these examples on a Windows box and thus running…
Andreas Grech
  • 105,982
  • 98
  • 297
  • 360
1
2 3
99 100