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

How does ifstream's eof() work?

#include #include int main() { std::fstream inf( "ex.txt", std::ios::in ); while( !inf.eof() ) { std::cout << inf.get() << "\n"; } inf.close(); inf.clear(); inf.open( "ex.txt", std::ios::in ); …
roxrook
  • 13,511
  • 40
  • 107
  • 156
51
votes
5 answers

`getchar()` gives the same output as the input string

I am confused by a program mentioned in K&R that uses getchar(). It gives the same output as the input string: #include main(){ int c; c = getchar(); while(c != EOF){ putchar(c); c = getchar(); } } Why…
Shubham
  • 21,300
  • 18
  • 66
  • 89
51
votes
11 answers

Checking for an empty file in C++

Is there an easy way to check if a file is empty. Like if you are passing a file to a function and you realize it's empty, then you close it right away? Thanks. Edit, I tried using the fseek method, but I get an error saying 'cannot convert…
Crystal
  • 28,460
  • 62
  • 219
  • 393
51
votes
10 answers

What is EOF in the C programming language?

How do you get to see the last print? In other words what to put in for EOF? I checked the definitions and it says EOF is -1. And if you enter Ctrl-D you won't see anything. #include int main() { int c; while((c = getchar() != EOF)) { …
Chris_45
  • 8,769
  • 16
  • 62
  • 73
45
votes
5 answers

What is value of EOF and '\0' in C

I know that EOF and '\0' are of type integers, but if so shouldn't they have a fixed value? I printed both and got -1 for EOF and 0 for '\0'. But are these values fixed? I also had this int a=-1; printf("%d",a==EOF); //printed 1 Are the value for…
theReverseFlick
  • 5,894
  • 8
  • 32
  • 33
43
votes
1 answer

Vim show newline at the end of file

Using the set eol option Vim automatically adds a newline to the end of the file when it's saved. I have this option on but I would like to be able to see this newline in Vim, so I know that it's actually there. For example with a file in Vim: And…
Keith Smiley
  • 61,481
  • 12
  • 97
  • 110
42
votes
9 answers

I'm trying to understand getchar() != EOF

I'm reading The C Programming Language and have understood everything so far. However when I came across the getchar() and putchar(), I failed to understand what is their use, and more specifically, what the following code does. main() { int c; …
Paolo Bernasconi
  • 2,010
  • 11
  • 35
  • 54
41
votes
4 answers

How to use EOF to run through a text file in C?

I have a text file that has strings on each line. I want to increment a number for each line in the text file, but when it reaches the end of the file it obviously needs to stop. I've tried doing some research on EOF, but couldn't really understand…
Tyler Treat
  • 14,640
  • 15
  • 80
  • 115
40
votes
10 answers

Can we write an EOF character ourselves?

Most of the languages like C++ when writing into a file, put an EOF character even if we miss to write statements like : filestream.close However is there any way, we can put the EOF character according to our requirement, in C++, for an…
Apoorv Saxena
  • 4,086
  • 10
  • 30
  • 46
37
votes
4 answers

Spring Rest Template usage causes EOFException

I'm receiving java.io.EOFException's when using Spring REST template on Android. The stacktrace cause reads like this: Caused by: java.io.EOFException at libcore.io.Streams.readAsciiLine(Streams.java:203) at…
Sebastian Roth
  • 11,344
  • 14
  • 61
  • 110
36
votes
5 answers

Python 3: EOF when reading a line (Sublime Text 2 is angry)

while True: reply = input('Enter text') if reply == 'stop': break print(reply.upper()) The result was: Enter text:Traceback (most recent call last): File "C:\PythonProjects\5.py", line 2, in reply = input('Enter…
Kifsif
  • 3,477
  • 10
  • 36
  • 45
34
votes
2 answers

IntelliJ IDEA: send EOF symbol to Java application

When running a command-line Java application from IntelliJ IDEA, is it possible to send EOF symbol to the program awaiting input? In console this can be done using ctrl-d combination but in IDEA it doesn't work.
Tvaroh
  • 6,645
  • 4
  • 51
  • 55
32
votes
7 answers

How do you read scanf until EOF in C?

I have this but once it reaches the supposed EOF it just repeats the loop and scanf again. int main(void) { char words[16]; while(scanf("%15s", words) == 1) printf("%s\n", words); return 0; }
JJRhythm
  • 633
  • 3
  • 10
  • 16
30
votes
5 answers

Token error: EOF in multi-line statement

The following code gives me this error "Token Error: EOF in multi-line statement". What is this error? How can I fix it? import easygui import time namegui = easygui.enterbox(msg='Enter your name:', title='Name query', default='Gian') situationgui =…
gian848396
  • 459
  • 1
  • 8
  • 24
29
votes
4 answers

Vim no end of line on last line or eof

I am trying to setup vim to skip adding eol on last line or eof, i have tried this :set binary :set noeol :w which is not perfect cause binary override filetype for later use. Any other option to set this, i don't need newline on last line.