Solved

display single character

Posted on 2000-02-29
10
253 Views
Last Modified: 2010-04-15
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
Comment
Question by:kennethtan
  • 3
  • 2
  • 2
  • +3
10 Comments
 
LVL 2

Expert Comment

by:curri
ID: 2570194
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
 
LVL 2

Expert Comment

by:curri
ID: 2570213
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
 
LVL 3

Expert Comment

by:Iexpert
ID: 2572360
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 3

Expert Comment

by:Iexpert
ID: 2572378
0
 
LVL 3

Expert Comment

by:marcjb
ID: 2574205
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
 

Author Comment

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

thanks
0
 
LVL 7

Expert Comment

by:KangaRoo
ID: 2579850
It appears that UNXGETCH implements getch(). Did you try it?
0
 

Accepted Solution

by:
nadt earned 50 total points
ID: 2581364
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
 
LVL 3

Expert Comment

by:Iexpert
ID: 2588442
? I posted a portable getch() for UNIX ! ?
0
 
LVL 7

Expert Comment

by:KangaRoo
ID: 2595282
??
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question