LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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


Reply
  Search this Thread
Old 10-10-2003, 06:56 AM   #1
captainstorm
Member
 
Registered: Jun 2003
Location: Oricola, Italy
Distribution: RH 9, so far
Posts: 261

Rep: Reputation: 31
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.
 
Old 10-10-2003, 07:06 AM   #2
lehrig
LQ Newbie
 
Registered: Oct 2003
Posts: 8

Rep: Reputation: 0
This is done with:
getch()

For more see:
man getch
 
Old 10-10-2003, 07:08 AM   #3
Xiangbuilder
Member
 
Registered: Apr 2003
Location: Shandong province China
Distribution: fedora core 1.0
Posts: 206

Rep: Reputation: 30
How about string, or character array?

Last edited by Xiangbuilder; 10-10-2003 at 07:10 AM.
 
Old 10-10-2003, 07:32 AM   #4
Mohsen
Member
 
Registered: Feb 2003
Location: Iran
Distribution: Solaris 10
Posts: 201

Rep: Reputation: 30
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++.
 
Old 10-10-2003, 08:56 AM   #5
captainstorm
Member
 
Registered: Jun 2003
Location: Oricola, Italy
Distribution: RH 9, so far
Posts: 261

Original Poster
Rep: Reputation: 31
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?
 
Old 10-10-2003, 10:34 AM   #6
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Does this help?
http://www.linuxquestions.org/questi...hreadid=102330
 
Old 10-11-2003, 05:14 AM   #7
Mohsen
Member
 
Registered: Feb 2003
Location: Iran
Distribution: Solaris 10
Posts: 201

Rep: Reputation: 30
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
getchar() satellite Programming 10 12-24-2017 02:47 PM
getchar() question h/w Programming 3 12-23-2003 05:53 PM
getchar() NSKL Programming 18 01-11-2003 11:19 AM
getchar() not working? lackluster Programming 3 06-24-2002 09:09 AM
getchar() Winter Programming 6 05-11-2002 02:49 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration