I can't use conio.h on Linux since its a DOS header. Thus you may have to excuse 3 functions of NCURSES am gonna use to emulate the getche() with echo off as required for your output. [NCURSES has only getch() and certain key-break/check functions to use along with it.]
1. initscr() - Required to start a working window for manipulating I/O. Mandatory for ncurses programs, segfaults else.
2. noecho() - Turns off echo. As your program demands.
3. endwin() - To close the screen started. Complements the 1st allowance. You can treat it as one.
(One thing I don't understand is, getche is supposed to getch() and echo right? Why doesn't your output have any characters then? Anyway, I used noecho() to do so.)
Ps. You have exit() under stdio.h probably, while I need to use stdlib.h. I have no use of stdio.h in my program and hence I guess you can allow me this one more too.
Program:
Code:
#include<ncurses.h>
#include<stdlib.h>
int main()
{
[B]initscr();
noecho();[/B]
printw("Hello!\nContinue(y/n)\n");
switch (getch())
{
case 121:
main();
break;
case 89:
main();
break;
}
printw("Bye,press any key to exit");
getch();
[B]endwin();[/B]
exit(0);
}
I don't expect this to pass or something, just wished to show that jumping over from TurboCrap stuff to standard code (And even Linux, for that matter) is easier than what most think.
Compile as:
Code:
gcc name.c -o outname [B]-lncurses[/B]
Outputs as:
Code:
Hello!
Continue(y/n)
Hello!
Continue(y/n)
Bye,press any key to exit