?
Solved

use of getch() function in codewarrior

Posted on 2003-03-27
7
Medium Priority
?
765 Views
Last Modified: 2012-06-27
I am writing a simple maze program, and am trying to use the getch() funtion in conio.h  for inputing a move without pressing enter.  I got getch() to work , but that was using visual c++, and when i brought it to school and used codewarrior to compile it didnt work.  i have downloaded every version of conio.h i could find, and nothing works.  We also us the AP Stationary (if that would affect it).  i was woundering if anyone has any examples of working getch() in codewarrior, or anything that might help.  Thanks.
0
Comment
Question by:nelag
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 2

Expert Comment

by:bkrahmer
ID: 8223087
DOS is a horrible platform to use as a basis of cross-platform development.  My suggestion is to use VC, and move on.  In the real world, you don't program for DOS.  :)

brian
0
 

Author Comment

by:nelag
ID: 8240796
thanks for the advice, but i have to program for dos because im at school, and i dont make the decisions. :)

*** im still open for answers.
0
 

Author Comment

by:nelag
ID: 8248832
ok i got the getch() function to work, but it still makes me press enter. the pressing enter part is the whole reason i wanted to use getch().

here is my code:

#include <iostream.h>
#include "conio.h"

int __getch(void);
int __kbhit(void);

int main()
{
int hi;
hi = __getch();
cout << endl <<hi;
return 0;
}    

any help would be great.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:nelag
ID: 8257635
thanks for the help guys, but i got the answer myself. :P
Now i know no one will probably read this, but i will post the working code for other people that ask questions and don't get any (usable) response, no affence bkrahmer.

i had to use the __initscr() function also found in the conio.h file, i had no idea what it did, so i tried it and it worked.

#include <iostream.h>
#include "conio.h"

int __getch(void);
void __initscr(void);

int main()
{
int hi;
__initscr(); // just put it there and it worked
hi = __getch();
cout << endl <<hi;
return 0;
}

i guess i accept my own answer??
0
 

Author Comment

by:nelag
ID: 8257708
hey, i didnt realize you cant really accept your own answer, even tough it is the right one.

p.s. that might be a good feature to add in the future. perhaps.
0
 
LVL 9

Expert Comment

by:tinchos
ID: 9551132
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

PAQ/Refund

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 9594666
PAQed, with points refunded (85)

Computer101
E-E Admin
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

764 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