tags:

views:

911

answers:

2

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?

+10  A: 

In Windows, use ^Z (CtrlZ) to enter an EOF.

For comparison, the way to enter an EOF on Unix-like systems is ^D.

Greg Hewgill
Some useful addition: If you are on a line that's not empty, you will have to double press ^D: Pressing it one time will flush that line, pressing it another time will send EOF. If you are on an empty line, one ^D is enough.
Johannes Schaub - litb
just curious, how did you do the images of keys? looks cool.
Anders K.
That's the <kbd> HTML element.
Greg Hewgill
ah ok! thank you
Anders K.
Thanks, exactly what I was looking for.
Andreas Grech
+3  A: 

Refer EOF

Windows: Ctrl+Z
Unix :Ctrl+D
aJ
+1 Thanks for the reference
Andreas Grech