Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   What is the alternative for getch() in C - Linux (http://www.go4expert.com/forums/alternative-getch-c-linux-t28690/)

smp 8Jul2012 17:45

What is the alternative for getch() in C - Linux
 
Guys,

I am writing a program. In a situation I want to print something and go to clear the screen but when i clear the screen the printed text also gets cleared. I want it such that after the print we have to click a key for the screen to get cleared. Is there a command or code which does that.

Code :

In TC or TC++
Code:

printf("Click to continue");
getch();
system("clear");

But in linux there is no header "conio" and hence no getch(). So i cant do what the above code snipped does. Please help.

Cristi1213 9Jul2012 17:30

Re: What is the alternative for getch() in C - Linux
 
You could try system("pause")....it should work

smp 10Jul2012 16:56

Re: What is the alternative for getch() in C - Linux
 
thanks cristi.....

But that option is there for DOS.... I am running linux....Pause comand is not there in linux

smp 11Jul2012 17:12

Re: What is the alternative for getch() in C - Linux
 
thanks cristi, i got the command while searching the alternative for "pause" command in linux.
its

Code:

system(read -n1 -r -p "text here");


All times are GMT +5.5. The time now is 07:21.