C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 7th, 2004, 10:54 PM
eviny eviny is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 1 eviny User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Accepts input character without pressing [ENTER]

hi all ,
i am new to this forum ..
but i have a question and i cant find the answer anywhere on the internet ..
i need to get an user input and accepts the input without the need of the user pressing enter ...
below is my code ... i am running this code under solaris 9

if(nRetVal >= 0)
{
while(DbObj.getNextTrans()>=0) //getNextRec if getNextRec more than 0 (record exist)
DbObj.printTransDetails(); //call function printTransDetails to output record
char breakRec;
cout << "Press [m] to Return to Main Menu" << endl;
breakRec = getchar();
if(breakRec == 'm') //check if user input 'm'
{
return -1;
}

the problem with this code is that after the user enters m .. he needs to press enter or else the system wouldnt
accept m as the input ..
anyone ? please help ...
thanks in advance

Reply With Quote
  #2  
Old January 23rd, 2005, 04:51 PM
ubergeek ubergeek is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2005
Posts: 600 ubergeek User rank is Private First Class (20 - 50 Reputation Level)ubergeek User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 40 m 27 sec
Reputation Power: 4
Send a message via AIM to ubergeek
does it have to be "m" ?
why not just have it be "Press any key to return to the main menu" and use system("pause") ?
or, use getchar() and have it be "Press [ENTER] to return to the main menu"

Last edited by ubergeek : January 23rd, 2005 at 07:28 PM. Reason: added another solution

Reply With Quote
  #3  
Old January 24th, 2005, 04:53 PM
Anibal Anibal is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 176 Anibal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 20 m 48 sec
Reputation Power: 4
Hey! The problem is that getchar() requires the user to press enter. In windows, for example, there's a function like bioskey which allows you to detect the key code without enter. Try finding a function like that for solaris

Reply With Quote
  #4  
Old January 24th, 2005, 05:03 PM
ubergeek ubergeek is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2005
Posts: 600 ubergeek User rank is Private First Class (20 - 50 Reputation Level)ubergeek User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 40 m 27 sec
Reputation Power: 4
Send a message via AIM to ubergeek
there's kbhit(), but that only tells you if a key has been pressed, not which one was pressed

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Accepts input character without pressing [ENTER]


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway