Re: Pass an EOF instead of pressing enter



In article <1167539258.863874.14460@xxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Camellia <breakfastea@xxxxxxxxx> wrote:

I input "abcd" follows by an EOF(Ctrl + d) instead of pressing enter,
and the program prints "abcd" on the screen. And then I pass an EOF
signal the program ends.

My question is why doesn't the program end the first it encounters the
EOF after the "abcd"?

This is really a question about your operating system, not about C.
Unix behaves as you describe - the EOF key only sends EOF after a
newline or another EOF.

And also if I DO press enter after "abcd", do I pass the characters
'a', 'b', 'c', 'd', '\n' to the program?

Yes. This is the usual situation. Pressing EOF without a newline
first is a way of sending a line without a newline at the end.

-- Richard

--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
.



Relevant Pages

  • Re: EOF & Learning C
    ... >> Programming Language' (Second Edition). ... >> enter key just makes a newline and dosen't terminate the application ... What exactly is the function of EOF? ... sure all output lines end with a newline. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Some suggestion required regarding get line functionality.
    ... char *temp_buff; ... position of pos ... but we need to put newline at the end od buf;So ... Why return NULL if you hit EOF? ...
    (comp.lang.c)
  • Re: Missing EOF
    ... >> Some files I must process have a EOF and some files don't. ... > AFAIK files don't really contain an EOF at their end. ... > used in programming to allow the programmer to know that a file ... I believe he's really asking for a way of adding a final newline ...
    (comp.unix.shell)
  • Re: reading file to list
    ... eof during read. ... no newline at the end can't be read with it. ... items read, sequence as end marker, eof, eol, predicate ... include only those elements that pass a filter. ...
    (comp.lang.lisp)
  • Re: Segfault question.
    ... >>because the EOF virtually always follows a newline and will be thus at the ... >>where the EOF does show up without being preceeded by a newline? ... I can't just live with a segfault unless I'm sure of the data I'm ... The thing about undefined behavior is ...
    (comp.lang.c)