3

I'm currently learning C with K&R and I'm having a hard time sending EOF simulation through cmd. I was trying Ctrl + Z which did nothing.

In some cases Enter is doing the work and in other cases nothing does it.

Thanks in advance for any help.

Quaker
  • 1,483
  • 3
  • 20
  • 36
  • Ctrl-z is right for Windows, however iirc the effect is not immediate. You still have to hit Enter afterward. – FatalError May 14 '12 at 19:18
  • I have tried them both, didn't work. – Quaker May 14 '12 at 19:20
  • [This answer](http://stackoverflow.com/a/1793631/866193) to a similar question says that Ctrl-Z + Enter is the way to go. – Sam DeHaan May 14 '12 at 19:24
  • Hi Sam thanks but I was saying that I have tried Ctrl+Z -> Enter and it didn't work. In the case I mentioned when Enter only did the job, it was nothing but Enter. – Quaker May 14 '12 at 19:27

2 Answers2

2

Assuming you're on Windows, the situation is that you basically have to do the ctrl+Z at the beginning of a line -- i.e., you have to have hit enter, then do the ctrl+Z, then (depending on how the input is being read) possibly enter again.

You can also use F6 to signal the end of the input. At least in most cases, this will work even when/if it does not immediately follow an enter.

Unfortunately, Windows provides enough different ways and modes to read input, that it's a little hard to state a whole lot with absolute certainty unless we know the compiler you're using (or, more specifically, the standard library) as well as the exact code you've written. Under normal circumstances, just hitting enter should not be detected as end of file, but your code could be treating an empty line as the end of input.

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
  • I know it's not perfect but it should work, or at least print 'All good baby...' http://pastebin.com/MGgGhHiP – Quaker May 14 '12 at 22:40
0

In a Windows 7 console window, I had success pressing F6 followed by Enter. F6 produces the end-of-file ^Z symbol at the command prompt.

Ctrl+Z causes the console window to quit execution, not only the user program.

yellowjacket05
  • 149
  • 1
  • 2
  • 12