Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 the compiled exe files from the cmd prompt.

To test the example above, how do I simulate an EOF? That is, basically how can I make the loop stop when testing the example from the command prompt?

like image 817
Andreas Grech Avatar asked Jul 13 '09 11:07

Andreas Grech


People also ask

How do you indicate EOF?

On Linux systems and OS X, the character to input to cause an EOF is Ctrl - D . For Windows, it's Ctrl - Z .

What is EOF equivalent to?

The End of the File (EOF) indicates the end of input. After we enter the text, if we press ctrl+Z, the text terminates i.e. it indicates the file reached end nothing to read.

How do you enter the EOF indicator on Windows?

You can simulate EOF with CTRL+D (for *nix) or CTRL+Z then Enter (for Windows) from command line.


1 Answers

To enter an EOF, use:

  1. ^Z (CtrlZ) in Windows
  2. ^D on Unix-like systems
like image 146
Greg Hewgill Avatar answered Sep 17 '22 17:09

Greg Hewgill