There have been similar posts like yours in this & related forums before. AFAIK unix C libraries doesnt provide any function that returns the character from std input on keypress alone . You need to press the line feed(Enter) key also for the character to be read into the buffer. Functions like getchar() operate like this.
You can simulate getch()/getche() in a UNIX environment by using the select/poll methods. You need to keep polling the ioctl of STDIN and select the key press event.
Here is some code , which was posted to an earlier question by rbobbit. This might be helpful for you.
I am posting it here below. It mimics the getch()/kbhit()
functions of conio.h in VC++.
if you want to know how it works, you can try the man pages of select & poll. And the credit for this post goes
to rbobbit, not me
Hope this is useful.
Anand
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <termios.h>
/**********************************************************
* An attempt at mimicking the kbhit() function availableon
* DOS implementations for *nix environments. The terminal
* should have already been set up appropriately.
**********************************************************/
int kbhit(void)
{
fd_set set;
struct timeval tv;
int tmp;
int result;
tv.tv_sec=tv.tv_usec=0; /* select will not wait even a microsecond */
FD_ZERO(&set); /* Must be done to clear the file descriptor set */
FD_SET(0,&set); /* Set watch on stdin (file descriptor 0) */
/* Find out if characters are available in stdin */
tmp=select(1,&set,NULL,NULL,&tv);
if (-1==tmp) {
/* An error occurred with select */
result=-1;
} else {
/* Are there characters available? */
if (FD_ISSET(0,&set)) {
/* Yes */
result=1;
} else {
/* Nope */
result=0;
}
}
return result;
}
int main(void)
{
struct termios new;
struct termios save;
int quit=0;
/* Get the current terminal settings */
if (tcgetattr(0,&save)!=0) {
fputs("Failed to init",stderr);
return EXIT_FAILURE;
}
/* We'll use save as a copy to restore the original
* settings later
*/
new=save;
/* Set up terminal so that characters are not
* echoed and turn off canonical mode.
*/
new.c_cc[VMIN]=1;
new.c_lflag&=~ICANON;
new.c_lflag&=~ECHO;
/* Send the new settings to the terminal */
tcsetattr(0,TCSANOW,&new);
puts("A program that does nothing, hit q or Q to quit"

;
while (!quit) {
puts("waiting..."

;
sleep(1);
/* Check to see if the user entered any data */
if (kbhit()==1) {
/* Got some input, just process the 1st character
* You could alternatively process all the user
* input, which would make more sense in most cases
*/
int c=getchar();
switch(toupper((unsigned char)c)) {
case 'Q':
/* User wants to quit, set the flag */
quit=1;
break;
default:
printf("You entered %c\n",c);
}
}
/* Do some other processing here */
}
puts("Quitting..."

;
/* Restore the terminal to its original settings */
if (tcsetattr(0,TCSANOW,&save)!=0) {
fputs("Failed to restore terminal",stderr);
return EXIT_FAILURE;
}
return 0;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Mail me at abpillai@excite.com if you want additional help. I dont promise that I can solve your problem, but I will try my best.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~