Solved

display single character

Posted on 2000-02-29
10
250 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
 
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
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
UPD maximums on Red Hat 6 110
Setting nameservers after res_init fails doing res_query 2 85
An API detour question 7 79
outlook office 365 8 84
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

910 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now