Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
10-10-2003, 06:56 AM
|
#1
|
Member
Registered: Jun 2003
Location: Oricola, Italy
Distribution: RH 9, so far
Posts: 261
Rep:
|
about getchar()
Hello all. Good morning.
The getchar() function always treat the "return" as one character and I have to use 2 getchar() everytime to eliminate the redundent "return". For example,
m_value = getchar();
getchar(); // this one is to mask the redundent "return" character.
Anybody knows if there is a way to result an "instant" character get and I do not need to push the "enter" button after typing the character?
Thank you very much.
|
|
|
10-10-2003, 07:06 AM
|
#2
|
LQ Newbie
Registered: Oct 2003
Posts: 8
Rep:
|
This is done with:
getch()
For more see:
man getch
|
|
|
10-10-2003, 07:08 AM
|
#3
|
Member
Registered: Apr 2003
Location: Shandong province China
Distribution: fedora core 1.0
Posts: 206
Rep:
|
How about string, or character array?
Last edited by Xiangbuilder; 10-10-2003 at 07:10 AM.
|
|
|
10-10-2003, 07:32 AM
|
#4
|
Member
Registered: Feb 2003
Location: Iran
Distribution: Solaris 10
Posts: 201
Rep:
|
As many times answered (even once to me) in this forum, there's a NCurses function `getch()' like the one in Borland C++. You can see Similar Threads below.
Quote:
How about string, or character array?
|
If you mean how to read them the answer is gets() or `scanf("%s")' in C , and `cin >> myStr' in C++.
|
|
|
10-10-2003, 08:56 AM
|
#5
|
Member
Registered: Jun 2003
Location: Oricola, Italy
Distribution: RH 9, so far
Posts: 261
Original Poster
Rep:
|
thank you lehrig and Mohsen, but when I use cbreak() or halfdelay(int) in the program, I always get a "segment fault (core dumped)" error when calling either of these funtion.
But without initialization, the program is in nodelay mode and I could not type anything before the getch() returns.
How can I solve this problem?
|
|
|
10-10-2003, 10:34 AM
|
#6
|
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536
Rep:
|
|
|
|
10-11-2003, 05:14 AM
|
#7
|
Member
Registered: Feb 2003
Location: Iran
Distribution: Solaris 10
Posts: 201
Rep:
|
The Segmentation Violation can be because you should always call initscr() at the beginning og a NCurses program, and if not there would be SIGSEGV
|
|
|
All times are GMT -5. The time now is 03:04 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|