Pass an EOF instead of pressing enter

Discussion in 'C Programming' started by Camellia, Dec 31, 2006.

  1. Camellia

    Camellia Guest

    Hi all,

    I'll get straight into it.

    When I try to run the code:
    .....
    while (scanf("%c", &c) == 1)
    printf("%c", c);
    .....
    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"?
    And also if I DO press enter after "abcd", do I pass the characters
    'a', 'b', 'c', 'd', '\n' to the program?

    Any suggestions are appreciated.
     
    Camellia, Dec 31, 2006
    #1
    1. Advertising

  2. In article <>,
    Camellia <> 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.
     
    Richard Tobin, Dec 31, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mg
    Replies:
    5
    Views:
    1,052
    Vikram.NET
    Jul 14, 2003
  2. Jerry
    Replies:
    4
    Views:
    1,183
    John Saunders
    Jul 25, 2003
  3. Philip Townsend

    button focus and pressing enter

    Philip Townsend, Aug 14, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    8,781
  4. Camellia

    Pass an EOF before pressing enter

    Camellia, Dec 31, 2006, in forum: C Programming
    Replies:
    9
    Views:
    394
    Richard Tobin
    Jan 2, 2007
  5. HopfZ
    Replies:
    0
    Views:
    614
    HopfZ
    Aug 28, 2006
Loading...

Share This Page