David Maddox wrote:... I can get it to run perfectly if I have the user type in a signifying phrase ("DONE"), but I cant figure out the end of file part...
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Kurt Van Etten wrote:...I suspect this behavior may be rather system dependent, though. On Unix you would want to enter Ctrl-D instead of Ctrl-Z, but I wonder if this also holds for Apple? ...
In UNIX and AmigaDOS, the translation of the keystroke to EOF is performed by the terminal driver, so a program does not need to distinguish terminals from other input files. By default, the driver converts a Control-D character at the start of a line into an end-of-file indicator. To insert an actual Control-D (ASCII 04) character into the input stream, the user precedes it with a "quote" command character (usually Control-V).
Kurt Van Etten wrote:... Even if you get this part to work, though, it has a big drawback--once you have an end-of-file condition on System.in, you will no longer be able to get further input from the keyboard. This means that there would be no way for you to get a response to your menu in the remainder of your program.
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
marc weber wrote:I admit I'm not sure of the "best" way to handle this. One option would be when an end-of-file value is detected, call close() on the Scanner and set a flag to break out of the loop...
Kurt Van Etten wrote:... I guess my point is that the requirement in the original post that an EOF be used instead of a sentinel value in the input doesn't seem to be reasonable. On the other hand, if the user is supposed to enter a quoted EOF character, then that is no different from any other sentinel value, and I think I'd want to have the user enter something a little easier to type in.
... In the specs, the requirement is that the user is supposed to type the end of file character to signify when they are done entering names...
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Kurt Van Etten wrote:... There's not really a need for any additional checks for EOF in my code example--the only way to break out of the input loop is to cause an EOF condition...
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |