Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   Input without pressing enter? (http://www.velocityreviews.com/forums/t315796-input-without-pressing-enter.html)

LaBird 10-16-2003 08:22 AM

Input without pressing enter?
 
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).



Andreas Kahari 10-16-2003 08:51 AM

Re: Input without pressing enter?
 
In article <bmlkfc$g0j$1@www.csis.hku.hk>, 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

Joona I Palaste 10-16-2003 08:55 AM

Re: Input without pressing enter?
 
Andreas Kahari <ak+usenet@freeshell.org> scribbled the following:
> In article <bmlkfc$g0j$1@www.csis.hku.hk>, 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 (palaste@cc.helsinki.fi) ------------- 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

Andreas Kahari 10-16-2003 09:09 AM

Re: Input without pressing enter?
 
In article <bmlmds$7hr$1@oravannahka.helsinki.fi>, Joona I Palaste wrote:
> Andreas Kahari <ak+usenet@freeshell.org> 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

John L 10-16-2003 09:15 AM

Re: Input without pressing enter?
 

"Joona I Palaste" <palaste@cc.helsinki.fi> wrote in message news:bmlmds$7hr$1@oravannahka.helsinki.fi...
> Andreas Kahari <ak+usenet@freeshell.org> scribbled the following:
> > In article <bmlkfc$g0j$1@www.csis.hku.hk>, 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.



LaBird 10-16-2003 09:32 AM

Re: Input without pressing enter?
 
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" <ak+usenet@freeshell.org> wrote in message
news:slrnbosn0p.3jt.ak+usenet@mx.freeshell.org...
> In article <bmlkfc$g0j$1@www.csis.hku.hk>, 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




Joona I Palaste 10-16-2003 10:26 AM

Re: Input without pressing enter?
 
Andreas Kahari <ak+usenet@freeshell.org> scribbled the following:
> In article <bmlmds$7hr$1@oravannahka.helsinki.fi>, Joona I Palaste wrote:
>> Andreas Kahari <ak+usenet@freeshell.org> 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 (palaste@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"I am looking for myself. Have you seen me somewhere?"
- Anon


All times are GMT. The time now is 05:26 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.