Link to home
Start Free TrialLog in
Avatar of nelag
nelag

asked on

use of getch() function in codewarrior

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.
Avatar of bkrahmer
bkrahmer

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
Avatar of nelag

ASKER

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.
Avatar of nelag

ASKER

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.
Avatar of nelag

ASKER

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??
Avatar of nelag

ASKER

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.
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
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial