Solved

display single character

Posted on 2000-02-29
10
251 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
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 recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

777 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