Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Input without pressing enter?

Reply
Thread Tools

Input without pressing enter?

 
 
LaBird
Guest
Posts: n/a
 
      10-16-2003
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).


 
Reply With Quote
 
 
 
 
Andreas Kahari
Guest
Posts: n/a
 
      10-16-2003
In article <bmlkfc$g0j$(E-Mail Removed)>, 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
 
Reply With Quote
 
 
 
 
Joona I Palaste
Guest
Posts: n/a
 
      10-16-2003
Andreas Kahari <(E-Mail Removed)> scribbled the following:
> In article <bmlkfc$g0j$(E-Mail Removed)>, 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 ((E-Mail Removed)) ------------- 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
 
Reply With Quote
 
Andreas Kahari
Guest
Posts: n/a
 
      10-16-2003
In article <bmlmds$7hr$(E-Mail Removed)>, Joona I Palaste wrote:
> Andreas Kahari <(E-Mail Removed)> 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
 
Reply With Quote
 
John L
Guest
Posts: n/a
 
      10-16-2003

"Joona I Palaste" <(E-Mail Removed)> wrote in message news:bmlmds$7hr$(E-Mail Removed)...
> Andreas Kahari <(E-Mail Removed)> scribbled the following:
> > In article <bmlkfc$g0j$(E-Mail Removed)>, 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.


 
Reply With Quote
 
LaBird
Guest
Posts: n/a
 
      10-16-2003
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> In article <bmlkfc$g0j$(E-Mail Removed)>, 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



 
Reply With Quote
 
Joona I Palaste
Guest
Posts: n/a
 
      10-16-2003
Andreas Kahari <(E-Mail Removed)> scribbled the following:
> In article <bmlmds$7hr$(E-Mail Removed)>, Joona I Palaste wrote:
>> Andreas Kahari <(E-Mail Removed)> 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 ((E-Mail Removed)) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"I am looking for myself. Have you seen me somewhere?"
- Anon
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting Input string without Pressing Enter of particular length bhutho C++ 3 10-28-2011 02:24 PM
Single character input without pressing 'Enter' unni.tallman Ruby 3 09-20-2006 12:56 PM
Single character input without pressing 'Enter' unni.tallman Python 3 09-20-2006 11:37 AM
Input without pressing Enter paul C++ 1 08-04-2003 02:59 PM
input=text fires Submit when pressing Enter Jerry ASP .Net 4 07-25-2003 01:38 PM



Advertisments