Solved

display single character

Posted on 2000-02-29
10
249 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
Comment Utility
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
Comment Utility
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
Comment Utility
0
 
LVL 3

Expert Comment

by:Iexpert
Comment Utility
0
 
LVL 3

Expert Comment

by:marcjb
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:kennethtan
Comment Utility
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
Comment Utility
It appears that UNXGETCH implements getch(). Did you try it?
0
 

Accepted Solution

by:
nadt earned 50 total points
Comment Utility
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
Comment Utility
? I posted a portable getch() for UNIX ! ?
0
 
LVL 7

Expert Comment

by:KangaRoo
Comment Utility
??
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
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…
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 opening and reading files in the C programming language.

744 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

17 Experts available now in Live!

Get 1:1 Help Now