LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-31-2004, 12:01 AM   #1
prasad514
LQ Newbie
 
Registered: Dec 2004
Location: india
Posts: 4

Rep: Reputation: 0
getch function


hello all

how to get characters without echoing on the standard output.
In windows we have getch() to do this ,but it is not working
in linux. I tried with all types of getch statements then
also it is not coming.

please suggest the answer for this
prasad
 
Old 12-31-2004, 12:16 AM   #2
Chrax
Member
 
Registered: Apr 2004
Distribution: Dapper
Posts: 167

Rep: Reputation: 31
I'm just starting to play with curses, and have found noecho() to do precisely that.

Then again, as I have just started playing, I am not fully aware of the purpose of everything I'm doing. (But I'm pretty sure about this, as it was in the man page.)
 
Old 12-31-2004, 04:01 AM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
do a search for getch or kbhit.
There are loads of threads on it.

billy.
 
Old 12-31-2004, 04:14 PM   #4
1337 Twinkie
Member
 
Registered: Jul 2004
Distribution: Fedora Core 2
Posts: 79

Rep: Reputation: 15
The ncurses library has a getch() function. However, getch() is just used to pass input to the program. noecho() initializes the program to not echo the input. The basic guide and some examples can be found here.

If you would like another example, I wrote a pong-style game using ncurses while I was learning C++.

Disclaimer- The actual gameplay code isn't all that spectacular and is not that efficient, but it should provide a decent example of how ncurses can be used
 
Old 01-03-2005, 05:15 AM   #5
deveraux83
Member
 
Registered: Jul 2003
Location: Malaysia
Distribution: Red Hat, Slackware 9.1
Posts: 76

Rep: Reputation: 15
I used to be caught up in this as well. ncurses actually implements getch() very similarly to the windows counterpart. The only thing is, you have to execute several other functions to make it work right such as noecho(), raw() and other functions (I haven't used ncurses in over 2 years, so I'm getting rusty). Also, if you want to do complicated keyboard manipulation, just look out for escape sequences (I'm not sure if windows did it this way -- haven't programmed in windows even longer).
 
Old 01-03-2005, 09:21 AM   #6
Marius2
Member
 
Registered: Jan 2004
Location: Munich
Distribution: SuSE 9.2, 10.2, 10.3, knoppix
Posts: 276

Rep: Reputation: 31
Try this, it should (roughly, hopefully :-)) behave like getch:

char getch_substitute(){
char ch;
read(0,&ch,1);
if(ch==91)read(0,&ch,1);
return ch;
}



HTH
 
Old 01-03-2005, 11:48 AM   #7
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: Gentoo, LFS, Debian,Ubuntu
Posts: 1,537

Rep: Reputation: 87
umm theres lots of things you can use


getchar
putchar
getc
fgetc
putc
fputc
ungetc


these all work with single character input and output

these are part of stdio.h
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Where is getch()....... rajsun Programming 2 03-28-2005 11:40 AM
getch() in FC2 natm Programming 3 10-20-2004 02:26 PM
Help with getch... darkarcon2015 Programming 4 09-12-2004 08:48 AM
getch in Linux? dummybert Programming 2 10-03-2003 02:43 AM
ncurses getch() deveraux83 Programming 3 08-06-2003 07:27 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration