Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

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
0
kennethtan
Asked:
kennethtan
  • 3
  • 2
  • 2
  • +3
1 Solution
 
curriCommented:
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.
0
 
curriCommented:
They are asking the same thing, in the context of linux(which is essentially a unix clone). Check:

http://www.experts-exchange.com/jsp/qShow.jsp?ta=linuxprog&qid=10295916 
0
 
IexpertCommented:
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
marcjbCommented:
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;
     }
0
 
kennethtanAuthor Commented:
reject because, the UNIX system that i am using does not allow me to use getch(), ie, i can only use getchar().

thanks
0
 
KangaRooCommented:
It appears that UNXGETCH implements getch(). Did you try it?
0
 
nadtCommented:
Try following code, this works:-

char readkey(int *isfunc)
{
  char temp;

  temp=getchar();
  if (temp==0)
  {
    *isfunct=0;
    temp=getchar();
  }
  return(temp);
}
 
use this function as-is in your program.  If the program wants to know which key has been hit , just say:-

  What_key=readkey(function_key);
 
now process what_key.  If it is up arrow or down arrow or some function key them `function_key' will be set to zero or else will have a trash value.  

Hope this helps
nadt
0
 
IexpertCommented:
? I posted a portable getch() for UNIX ! ?
0
 
KangaRooCommented:
??
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now