How do I read input if the end is not defined? What is end of file?

Modified on Wed, 10 Mar, 2021 at 5:27 PM

Input is always terminated by end of file/EOF in Kattis, so your solution can rely on this symbol being the last thing in the input. Depending on the programming language, there are many different ways to detect the EOF symbol.


To test that your program exits correctly at the end of input, you can run your program the same way as Kattis does. You typically do this by using a shell. This is sometimes known as "run your program in the terminal. Then you pipe in an input file to your program. The example below will run "my_program" and send input.txt on STDIN with an EOF symbol at the end.


./my_program < input.txt


It is also possible to signal the end of input when you run your program interactively. You typically do this by typing ^d (ctrl+d) on the keyboard. This will send the EOF signal to your program, and it should exit cleanly.


Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article