Input without pressing enter?

Discussion in 'C Programming' started by LaBird, Oct 16, 2003.

  1. LaBird

    LaBird Guest

    Dear all,

    I would like to ask if there is any C function that accept one
    keystroke as input, without printing out what the user presses
    and without the need to press enter as delimiter. getchar()
    can accept a character, but it needs user to press enter to
    accept the input.

    Thanks very much.

    Regards,
    LaBird (Benny).
     
    LaBird, Oct 16, 2003
    #1
    1. Advertising

  2. In article <bmlkfc$g0j$>, LaBird wrote:
    > Dear all,
    >
    > I would like to ask if there is any C function that accept one
    > keystroke as input, without printing out what the user presses
    > and without the need to press enter as delimiter. getchar()
    > can accept a character, but it needs user to press enter to
    > accept the input.


    There is no such function in C. Please read the FAQ at

    http://www.eskimo.com/~scs/C-faq/q19.1.html



    --
    Andreas Kähäri
     
    Andreas Kahari, Oct 16, 2003
    #2
    1. Advertising

  3. Andreas Kahari <> scribbled the following:
    > In article <bmlkfc$g0j$>, LaBird wrote:
    >> Dear all,
    >>
    >> I would like to ask if there is any C function that accept one
    >> keystroke as input, without printing out what the user presses
    >> and without the need to press enter as delimiter. getchar()
    >> can accept a character, but it needs user to press enter to
    >> accept the input.


    > There is no such function in C. Please read the FAQ at


    > http://www.eskimo.com/~scs/C-faq/q19.1.html


    It's not that easy to answer. It actually depends on your OS settings.
    It is fully possible that getchar() can receive characters as you type
    them from the keyboard. The point is that getchar() receives characters
    as they appear in stdin. But the connection between stdin and the
    keyboard is none of C's business.

    --
    /-- Joona Palaste () ------------- Finland --------\
    \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
    "A computer program does what you tell it to do, not what you want it to do."
    - Anon
     
    Joona I Palaste, Oct 16, 2003
    #3
  4. In article <bmlmds$7hr$>, Joona I Palaste wrote:
    > Andreas Kahari <> scribbled the following:

    [cut]
    >> There is no such function in C. Please read the FAQ at

    >
    >> http://www.eskimo.com/~scs/C-faq/q19.1.html

    >
    > It's not that easy to answer. It actually depends on your OS settings.
    > It is fully possible that getchar() can receive characters as you type
    > them from the keyboard. The point is that getchar() receives characters
    > as they appear in stdin. But the connection between stdin and the
    > keyboard is none of C's business.


    Do you by "settings" mean "buffered or unbuffered"?

    I believe that's what the parenthasis at the end addresses:

    (As an aside, note that simply using setbuf or setvbuf to
    set stdin to unbuffered will not generally serve to allow
    character-at-a-time input.)

    --
    Andreas Kähäri
     
    Andreas Kahari, Oct 16, 2003
    #4
  5. LaBird

    John L Guest

    "Joona I Palaste" <> wrote in message news:bmlmds$7hr$...
    > Andreas Kahari <> scribbled the following:
    > > In article <bmlkfc$g0j$>, LaBird wrote:
    > >> Dear all,
    > >>
    > >> I would like to ask if there is any C function that accept one
    > >> keystroke as input, without printing out what the user presses
    > >> and without the need to press enter as delimiter. getchar()
    > >> can accept a character, but it needs user to press enter to
    > >> accept the input.

    >
    > > There is no such function in C. Please read the FAQ at

    >
    > > http://www.eskimo.com/~scs/C-faq/q19.1.html

    >
    > It's not that easy to answer. It actually depends on your OS settings.
    > It is fully possible that getchar() can receive characters as you type
    > them from the keyboard. The point is that getchar() receives characters
    > as they appear in stdin. But the connection between stdin and the
    > keyboard is none of C's business.
    >


    In other words, you can do it in C using OS-specific library calls
    which are off-topic here. You need to ask in a newsgroup specific
    to the OS and/or compiler you are using. Maybe comp.unix.programmer
    or ... well, one of the others.

    Or, as Joona Palaste says, you can use standard C functions *after*
    using OS-specific commands to put your system into the appropriate
    state. Again, these are off-topic here and you should ask in
    an OS-specific newsgroup.

    John.
     
    John L, Oct 16, 2003
    #5
  6. LaBird

    LaBird Guest

    Dear Andreas,

    Thanks a lot. I am programming in Linux. According to your guide,
    now I can search from the web for the exact functions specific to
    Linux that serves what I wanted.

    Regards,
    LaBird (Benny).


    "Andreas Kahari" <> wrote in message
    news:...
    > In article <bmlkfc$g0j$>, LaBird wrote:
    > > Dear all,
    > >
    > > I would like to ask if there is any C function that accept one
    > > keystroke as input, without printing out what the user presses
    > > and without the need to press enter as delimiter. getchar()
    > > can accept a character, but it needs user to press enter to
    > > accept the input.

    >
    > There is no such function in C. Please read the FAQ at
    >
    > http://www.eskimo.com/~scs/C-faq/q19.1.html
    >
    >
    >
    > --
    > Andreas Kähäri
     
    LaBird, Oct 16, 2003
    #6
  7. Andreas Kahari <> scribbled the following:
    > In article <bmlmds$7hr$>, Joona I Palaste wrote:
    >> Andreas Kahari <> scribbled the following:

    > [cut]
    >>> There is no such function in C. Please read the FAQ at

    >>
    >>> http://www.eskimo.com/~scs/C-faq/q19.1.html

    >>
    >> It's not that easy to answer. It actually depends on your OS settings.
    >> It is fully possible that getchar() can receive characters as you type
    >> them from the keyboard. The point is that getchar() receives characters
    >> as they appear in stdin. But the connection between stdin and the
    >> keyboard is none of C's business.


    > Do you by "settings" mean "buffered or unbuffered"?


    > I believe that's what the parenthasis at the end addresses:


    > (As an aside, note that simply using setbuf or setvbuf to
    > set stdin to unbuffered will not generally serve to allow
    > character-at-a-time input.)


    No, I mean different settings than setbuf or setvbuf. I mean settings
    that affect the OS level, which goes deeper than stdin.

    --
    /-- Joona Palaste () ------------- Finland --------\
    \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
    "I am looking for myself. Have you seen me somewhere?"
    - Anon
     
    Joona I Palaste, Oct 16, 2003
    #7
    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. Jerry
    Replies:
    4
    Views:
    1,182
    John Saunders
    Jul 25, 2003
  2. paul
    Replies:
    1
    Views:
    526
    Jonathan Mcdougall
    Aug 4, 2003
  3. unni.tallman
    Replies:
    3
    Views:
    1,641
    Fredrik Lundh
    Sep 20, 2006
  4. bhutho
    Replies:
    3
    Views:
    588
    Turma 15 FCM
    Oct 28, 2011
  5. unni.tallman
    Replies:
    3
    Views:
    206
    James Edward Gray II
    Sep 20, 2006
Loading...

Share This Page