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

*Might* an unsigned char be equal to EOF?

When using fgetc to read the next character of a stream, you usually check that the end-of-file was not attained by if ((c = fgetc (stream)) != EOF) where c is of int type. Then, either the end-of-file has been attained and the condition will fail,…
Rémi Peyre
  • 410
  • 3
  • 12
10
votes
4 answers

End of file NullPointerException

What I wanted is to reach EOF by typing Ctrl + z from command line with BufferedReader reading from console. The following code does so. But the problem is, it issues a NullPointerException after reaching EOF. Is there a way to skip this exception?…
Tahmid Ali
  • 805
  • 9
  • 29
10
votes
6 answers

How to loop until EOF in Python?

I need to loop until I hit the end of a file-like object, but I'm not finding an "obvious way to do it", which makes me suspect I'm overlooking something, well, obvious. :-) I have a stream (in this case, it's a StringIO object, but I'm curious…
Ben Blank
  • 54,908
  • 28
  • 127
  • 156
10
votes
2 answers

What's the real reason to not use the EOF bit as our stream extraction condition?

Inspired by my previous question A common mistake for new C++ programmers is to read from a file with something along the lines of: std::ifstream file("foo.txt"); std::string line; while (!file.eof()) { file >> line; // Do something with…
Joseph Mansfield
  • 108,238
  • 20
  • 242
  • 324
10
votes
12 answers

reading input till EOF in java

In C++ if I wish to read input till the EOF I can do it in the following manner while(scanf("%d",&n)) { A[i]=n; i++; } I can then run this code as ./a.out < input.txt. What is the java equivalent of this code?
zer0nes
  • 175
  • 2
  • 3
  • 10
10
votes
3 answers

sscanf & newlines

I need to parse a response from a server like this: risposta: 200\n Len 1040\n Expire 30\n \n 1111111111111111111111111\n 1111111111111111111111111\n 1111111111111111111111111\n I'm trying with sscanf: sscanf(risposta, "%d\nLen %d\nExpire…
Gorgo
  • 456
  • 1
  • 7
  • 19
9
votes
1 answer

Use getline() without setting failbit

Is it possible use getline() to read a valid file without setting failbit? I would like to use failbit so that an exception is generated if the input file is not readable. The following code always outputs basic_ios::clear as the last line - even if…
Jeremiah
  • 512
  • 2
  • 5
  • 17
9
votes
5 answers

Boost serialization end of file

I serialize multiple objects into a binary archive with Boost. When reading back those objects from a binary_iarchive, is there a way to know how many objects are in the archive or simply a way to detect the end of the archive ? The only way I found…
Shnippoo
  • 193
  • 2
  • 10
9
votes
1 answer

Why does operator>> on complex not set eofbit if it reaches EOF?

I'm trying to read as many std::complex as possible from a file (or any std::istream). If the operation fails, I check for ios::eof(). If it hasn't been set, I assume that there was an error in parsing the data, and I can report to the user…
dennis
  • 192
  • 7
9
votes
5 answers

How to check for EOF in Python?

How do I check for EOF in Python? I found a bug in my code where the last block of text after the separator isn't added to the return list. Or maybe there's a better way of expressing this function? Here's my code: def get_text_blocks(filename): …
ajushi
  • 1,237
  • 4
  • 16
  • 28
9
votes
6 answers

Is EOF always negative?

Is EOF always negative? I'm thinking of writing a function that reads the next word in the input and returns the line number the word was found in or EOF if the end of the input has been reached. If EOF is not necessarily negative, the function…
Ree
  • 6,061
  • 11
  • 48
  • 50
9
votes
2 answers

How to read input until EOF in Lisp

How do I read an input stream until EOF in Lisp? In C, you might do it like this: while ((c = getchar()) != EOF) { // Loop body... } I would like to be able to pipe data to my Lisp programs without having to specify the data size in…
Fredrick Pennachi
  • 832
  • 1
  • 8
  • 17
9
votes
2 answers

ctrl-d didn't stop the while(getchar()!=EOF) loop

Here is my code. I run it in ubuntu with terminal. when I type (a CtrlD) in terminal, the program didn't stop but continued to wait for my input. Isn't CtrlD equal to EOF in unix? Thank you. #include main() { int d; …
Sam
  • 964
  • 3
  • 11
  • 24
8
votes
6 answers

Comparing unsigned char and EOF

when the following code is compiled it goes into an infinite loop: int main() { unsigned char ch; FILE *fp; fp = fopen("abc","r"); if(fp==NULL) { printf("Unable to Open"); exit(1); } while((ch =…
Amol Sharma
  • 1,521
  • 7
  • 20
  • 40
8
votes
3 answers

How to find EOF in a string in java?

I am working in school project. In that what they told is, I will be given a String which contains an actual program like.... import java.io.*\npublic class A{\n...........EOF And My job is to find particular regular expressions in that…
Muthu Ganapathy Nathan
  • 3,199
  • 16
  • 47
  • 77