但是在Unix/Linux底下 就必須自己寫個function囉~
#include<termios.h>
char getch(){
int i;//判斷是否有read到值
char ch;
struct termios _old, _new;
tcgetattr (0, &_old);
memcpy (&_new, &_old, sizeof (struct termios));
_new.c_lflag &= ~(ICANON | ECHO);
tcsetattr (0, TCSANOW, &_new);
i = read (0, &ch, 1);
tcsetattr (0, TCSANOW, &_old);
if (i == 1)/* ch is the character to use */
return ch;
else/* there was some problem; complain, return error, whatever */
printf("error!n");;
return 0;
}
沒有留言:
張貼留言