473,385 Members | 2,162 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,385 software developers and data experts.

Getch() in Linux

Does anyone know of a getch() equivalent that exists in linux?
I have just started doing some basic programming and am currently running Knoppix on CD.
So I'm not sure what kind of file library I have available.

Any help would be greatly appreciated;

GL
Jun 21 '06 #1
3 40195
Banfa
9,065 Expert Mod 8TB
What programming language are you talking about? C/C++?

In my MSVC I can find

getc
getchar
_getch

getc and getch are standard library functions and should be found in any C/C++ implementation.

_getch is a platform implementation function (denoted by the _ at the start of the name), a function provide by the platform in question to support the rest of the c standard library.

The closest standard library equivilent to _getch is getchar.
Jun 21 '06 #2
What programming language are you talking about? C/C++?

In my MSVC I can find

getc
getchar
_getch

getc and getch are standard library functions and should be found in any C/C++ implementation.

_getch is a platform implementation function (denoted by the _ at the start of the name), a function provide by the platform in question to support the rest of the c standard library.

The closest standard library equivilent to _getch is getchar.

Put the following text in to Gedit and save as getch.h
to use the function use mygetch()

works like a charm
Expand|Select|Wrap|Line Numbers
  1. /
  2.  
  3. #include <termios.h>
  4. #include <unistd.h>
  5.  
  6. int mygetch(void)
  7. {
  8. struct termios oldt,
  9. newt;
  10. int ch;
  11. tcgetattr( STDIN_FILENO, &oldt );
  12. newt = oldt;
  13. newt.c_lflag &= ~( ICANON | ECHO );
  14. tcsetattr( STDIN_FILENO, TCSANOW, &newt );
  15. ch = getchar();
  16. tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
  17. return ch;
  18. }
  19.  
/solution provided by kermi3 from this web posting http://cboard.cprogramming.com/archi...p/t-27714.html
Oct 1 '08 #3
@justaguy1010


Actually the compiler says that getchar() "is not declared in this scope".

I found out that you have to include the <cstdio> library.

Also, it appears this function can't read the '\r' character. (The enter key).

Anyway, thank you so much! you helped me a lot!
May 17 '19 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: voidstar | last post by:
Hi, I have the following problem: I use "getch" to monitor keypresses and the I use "cin" to input a string. When I type in 'y', the 'y' character appears, so I need to hit backspace before...
4
by: Crow | last post by:
Is there any way to make cin behave like getch()? Specifically, getch() returns immediately after a key is pressed and the cin family of input methods seem to block until a new line is...
4
by: zeroDontYouSpamMateytype | last post by:
Hi, Does anyone know if it's possible to write either a getch() (preferably Borland-style) or getche() function in C++ (I've posted the C equivalent of this question to CLC) without it being...
1
by: Ratheesh Kumar | last post by:
My doubt is on the working of getch() function based on the following observations 1) if the pressed key has an ascii code,only that can be read using a single call to getch() 2) if the key has...
45
by: simnav | last post by:
In the following code something strange happens ! If I keep pressed any of ALT+Arrow, keys, they are extracted two times from buffer then getch seems to stop; if I release and press again ALT+arrow...
5
by: Sankar | last post by:
Dear all, In my programming snippet compiled in Linux 2.6, I have a getch() , but the program when executed does not wait for my input.. fflush(stdin), fflush(stdout) - All these did not help. ...
4
by: jpenguin | last post by:
I am taking a college class for C++, they use Windows, at home I use linux. So for compatibility, can I use curse.h to perform like conio and getch()
3
by: shaheda begum | last post by:
Can anyone tel me the alternative for getch( ) in linux i.e the code so that the output should remain on the screen until the user presses enter.........
16
by: fuzhen | last post by:
If I want to "press any key to continue" in Windows, I can use getch() But the getch() isn't a standard C function So what should I to do in Linux?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.