473,411 Members | 2,285 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

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).
Nov 13 '05 #1
6 15755
In article <bm**********@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
Nov 13 '05 #2
Andreas Kahari <ak*******@freeshell.org> scribbled the following:
In article <bm**********@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 (pa*****@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
Nov 13 '05 #3
In article <bm**********@oravannahka.helsinki.fi>, Joona I Palaste wrote:
Andreas Kahari <ak*******@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
Nov 13 '05 #4

"Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message news:bm**********@oravannahka.helsinki.fi...
Andreas Kahari <ak*******@freeshell.org> scribbled the following:
In article <bm**********@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.
Nov 13 '05 #5
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*******@freeshell.org> wrote in message
news:sl**********************@mx.freeshell.org...
In article <bm**********@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

Nov 13 '05 #6
Andreas Kahari <ak*******@freeshell.org> scribbled the following:
In article <bm**********@oravannahka.helsinki.fi>, Joona I Palaste wrote:
Andreas Kahari <ak*******@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 (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"I am looking for myself. Have you seen me somewhere?"
- Anon
Nov 13 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: paul | last post by:
Have read the FAQ's and the forums but still cant find a good solution to this. I am using Linux and G++. I am trying to run a program which computes something or other and have the ability to...
7
by: Steve Wylie | last post by:
At work we use SNAP survey software. The software is capable of outputting a survey as a web page, in HTML, which we can tart up with Javascript for basic form validation if required. When the...
2
by: Andrew Parish | last post by:
I have a page with an input text box and a button which validates the text (see below). If I click inside the text box, the button is highlighted. If I enter some text inside the box and press...
10
by: mg | last post by:
I want to enter characters in a TextBox in a WebForm, press a Button in the WebForm, and read the characters that were typed into the TextBox from within the Button_Click event handler. The main...
4
by: peshrad | last post by:
Hi ! I'm working with Win 2K and Visual Studio 2003. I have a problem because pressing <ENTER> in a text input control causes a postback of my web form. Here comes some example code (already...
7
by: Hulo | last post by:
In a C program I am required to enter three numbers (integers) e.g. 256 7 5 on execution of the program. C:\> 256 7 5 There should be spaces between the three numbers and on pressing "enter",...
2
by: unni.tallman | last post by:
how can i read input from stdin, char by char, i want to get the character as soon as it is entered, without having to press 'Enter' after each character.
4
by: Newbie | last post by:
Hello I need to enter a string of the form abc (a string of characters followed by EOF) #include<stdio.h> #include<stdlib.h> #include<string.h> #define MAX 100 int main(void) {
2
by: jd | last post by:
I have several textboxes in which the end user can enter values. When the user presses the Enter key when in any of the textboxes, or leaves that textbox, I want a routine to run (mathematical...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.