05-20-06 06:15 PM
Hi all
Here's my test app - I want press a key ,display on screen
but it didn't print right.
Help me please;
//use -lstdc++
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include <iostream>
using namespace std;
int mygetch( ) { // getch()
struct termios oldt,newt;
int ch;
tcgetattr( STDIN_FILENO, &oldt );
newt = oldt;
newt.c_lflag &= ~( ICANON | ECHO );
tcsetattr( STDIN_FILENO, TCSANOW, &newt );
ch = getchar();
tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
return ch;
}
int main(int argc, char *argv[])
{
char ch_;
while(true)
{
ch=mygetch();
printf("%c",&ch_); // this will always print a blank -- why?
//printf("%d",&ch_); // this will always print -1073744410 -- why?
//std::cout << ch_; // this will print right char. also, std::cout <<
'\b' will not cause a backspace.
}
}
thank you very much
key9
[ Post a follow-up to this message ]
|