getch not working on HP-UX (125 Views)
Reply
Occasional Visitor
Orauser
Posts: 4
Registered: ‎04-04-2009
Message 1 of 7 (125 Views)

getch not working on HP-UX

Hi Experts,

I need to use getch in my application for masking the password. I am using getch from curses.h.

Below is the my code:

#include
#include

using namespace std;

int main()
{

cout<<"\nBefore getch";

getch();

cout<<"\nafter getch";

return 0;
}

I am compiling using aCC:

aCC -O -mt -AA +Z +eh +DAportable -w -Wc,-ansi_for_scope,off -DUNICODE -D_UNICODE -D_INCLUDE_STDC_A1_SOURCE -D_INCLUDE__STDC_A1_SOURCE -D_UNIX_ -D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS test.cpp -lcurses

It is compiling successfully but when i am running a.out then it is not waiting for the input and just printing the two statements and program ends.

bash-2.04$ a.out

Before getch
after getchbash-2.04$

Please guide me how to make getch() working on HP.

Thanks in advance for your help



Please use plain text.
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 2 of 7 (125 Views)

Re: getch not working on HP-UX

Hi:

From the 'getch(3X)' manpages:

int getch(void);

Regards!

...JRF...
Please use plain text.
Occasional Visitor
Orauser
Posts: 4
Registered: ‎04-04-2009
Message 3 of 7 (125 Views)

Re: getch not working on HP-UX

Thanks for your reply James but taking the output of getch in some variable is also not working.

nt main()
{

cout<<"\nBefore getch";

int val = getch();

cout<<"\nafter getch";

return 0;
}
Please use plain text.
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 4 of 7 (125 Views)

Re: getch not working on HP-UX

Hi (again):

I meant to suggest that if you capture the character returned by 'getch()' then you need to output whatever you captured.

Regards!

...JRF...
Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,782
Registered: ‎03-06-2006
Message 5 of 7 (125 Views)

Re: getch not working on HP-UX

>JRF: I meant to suggest that if you capture the character returned by 'getch()' then you need to output whatever you captured.

I get -1, possibly because?
If in nodelay mode and no data is available, ERR is returned.
#include
#include
int main() {
printf("Before getch:");
int char_in = getch();
printf("\nGot: %.2x|%c\n", (unsigned char)char_in, char_in);
}
Please use plain text.
Occasional Visitor
Orauser
Posts: 4
Registered: ‎04-04-2009
Message 6 of 7 (125 Views)

Re: getch not working on HP-UX

Hi James and Dennis,

Thanks a lot for your timely help!

I am getting below output after running your code snippet that displays the output of getch

bash-2.04$ a.out
Before getch:
Got: ff|ÿ
bash-2.04$

Please suggest me some way on how to fix this. Do i need to set some delay?

Regards
Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,782
Registered: ‎03-06-2006
Message 7 of 7 (125 Views)

Re: getch not working on HP-UX

>Please suggest me some way on how to fix this.

You are actually going to have to read the curses documentation. A good starting point would be curses_intro(3X).

I assume you need to tell curses what window or terminal to read from, possibly these:
initscr() or newterm() to initialise Curses and restores these settings when endwin()

>I need to use getch in my application for masking the password.

Perhaps you should toss getch and just turn on and off echoing?
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation