1

My Visual Studio still awaits input even after I keep entering a newline.

For example:

while ((c = fgetc(stdin)) != EOF)
{
   // do something
}

What should I enter that sends EOF to Visual Studio?

MD XF
  • 7,860
  • 7
  • 40
  • 71

1 Answers1

4

You can send an EOF with CTRL+D (for Linux) or CTRL+Z (for Windows) systems.

To elaborate, when fgetc() is waiting for an input from empty stdin, this key combination will simulate the EOF. In case, the stdin is not empty, you have to use the key combination twice (once to help flush the stdin, another to actually send the EOF).

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
  • @WeatherVane At this moment I have no idea and I don't have a windows system handy, will update you after I try. – Sourav Ghosh Dec 07 '16 at 17:37
  • Oops dear readers I had already removed: "Do you know why `scanf` requires *three* such sequences?" – Weather Vane Dec 07 '16 at 17:39
  • Control-D doesn't really send an EOF. It forces the current pending console input operation to return immediately with whatever has been typed up to that point. A lot of software assumes that the only reason an input request will return without reading any bytes is that it has reached the end, but control-D has no special meaning aside from cooked-mode consoles, unlike control-Z which MS-DOS interprets as an EOF indication if encountered within a text file. – supercat Dec 07 '16 at 17:49