RaaaAAA,
Не знаю насчет сразу выходит -спроси его.
Эта проблема неоднократно обсуждалась в инете - погугли.
Ткните пожалуйста носом в сурс. Еще вчера перекопал. Только на Лоре нашел, что если EOF не в пустой строке то вот так вот и на этом разошлись.
Пользователь решил продолжить мысль 07 Декабря 2013, 04:36:01:
Вот у буржуев есть на все ответы.
As others have already said, to handle Control-D, handle "end of file"s.
Control-D is a piece of communication between the user and the pseudo-file that you see as stdin. It does not mean specifically "end of file", but more generally "flush the input I typed so far". Flushing means that any read() call on stdin in your program returns with the length of the input typed since the last flush. If the line is nonempty, the input becomes available to your program although the user did not type "return" yet. If the line is empty, then read() returns with zero, and that is interpreted as "end of file".
So when using Control-D to end a program, it only works at the beginning of a line, or if you do it twice (first time to flush, second time for read() to return zero).