0

I am new to C programming, though I do know Java (more or less).

I am not understanding how EOF works, and due to this, am having constant trouble with every problem that uses a condition such as "while (c != EOF) {". Since I am not uploading a file to read from, but am rather a user typing input, how do I trigger EOF when I am finished typing my test text/input? I have read that the command "control+D" for a Mac should terminate something (what exactly?), but that ends up freezing Eclipse on my laptop.

What to do about all this?

Thanks so much!

ciamej
  • 6,918
  • 2
  • 29
  • 39
Anya
  • 21
  • 4
  • This appears to be a bug in Eclipse. Possibly relevant forum posts: http://www.eclipse.org/forums/index.php/t/80463/, https://bugs.eclipse.org/bugs/show_bug.cgi?id=159803. – Austin Mullins Jun 16 '14 at 21:27
  • Checkout this SO answer that explains how to enter an EOF in Eclipse. http://stackoverflow.com/questions/14908507/how-do-we-terminate-this-c-code/14916723#14916723. – R Sahu Jun 16 '14 at 21:30
  • Resolved: the Run Configurations trick in Eclipse did it. Thanks! – Anya Jun 16 '14 at 21:45
  • 2
    Note: When doing `while (c != EOF) {`, insure `c` is an `int`. – chux - Reinstate Monica Jun 16 '14 at 22:12

1 Answers1

3

If you run your program not from within eclipse, but in terminal, "control+D" will actually terminate the input and generate EOF.

If you run your program in terminal with a file redirected as the input:

 prog < file.in

Your program will receive the file contents as the input and EOF if it reads through all the contents.

It seems that "control+D" should work in eclipse, but it doesn't because of a bug. This: Passing End of Transmission (Ctrl + D) character in Eclipse CDT console might give you some more information and possibly a workaround.

Community
  • 1
  • 1
ciamej
  • 6,918
  • 2
  • 29
  • 39