Link to home
Start Free TrialLog in
Avatar of kennethtan
kennethtan

asked on

display single character

how can i display single character from keyboard entry immediately without entering the carriage return key, the UNIX workstation that i am using does not provide getch() but only getchar() (which requires a carriage return to be entered before displaying the keyboard entry)

how can i also read extended ASCII code, ie, 'up' arrow is being pressed ?

all codes be written in C

advance thanks
Avatar of curri
curri

There is NO portable, standard way to do this in C (since it is highly system dependant). However, most unix systems have ways to do that (they are not necessarily simple though :). The best solution for me has been using the 'curses' library. Type 'man curses' or 'man ncurses' to get help on it.
They are asking the same thing, in the context of linux(which is essentially a unix clone). Check:

https://www.experts-exchange.com/jsp/qShow.jsp?ta=linuxprog&qid=10295916 
Use the curses library
Compile with -lcurses

     #include<stdio.h>
     #include<curses.h>

     int main()
     {
     int c;

     initscr();
     cbreak();
     noecho();

     c = getch();
     printf("\nc is %c\n", (char)c);
     printf("c is %i\n", c);

     endwin();
     return 0;
     }
Avatar of kennethtan

ASKER

reject because, the UNIX system that i am using does not allow me to use getch(), ie, i can only use getchar().

thanks
It appears that UNXGETCH implements getch(). Did you try it?
ASKER CERTIFIED SOLUTION
Avatar of nadt
nadt

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
? I posted a portable getch() for UNIX ! ?