1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'C' started by smp, Jul 8, 2012.

  1. smp

    smp New Member

    Joined:
    Jul 8, 2012
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
  2. Cristi1213

    Cristi1213 New Member

    Joined:
    Jan 17, 2011
    Messages:
    6
    Likes Received:
    1
    Trophy Points:
    0
    You could try system("pause")....it should work
     
    smp likes this.
  3. smp

    smp New Member

    Joined:
    Jul 8, 2012
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    0
    thanks cristi.....

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

    smp New Member

    Joined:
    Jul 8, 2012
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    0
    thanks cristi, i got the command while searching the alternative for "pause" command in linux.
    its

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

Share This Page