*beginner help needed* getche() function 
Author Message
 *beginner help needed* getche() function

Evan,

What do you mean by "not recognized"?  Are you getting a compilation
error or a linking error?  What does it say?  I don't have version 1.0
handy, so I can't really duplicate what you are doing.  I am running
version 4.2 and version 5.0 is the latest available.

Ron Martin
Ann Arbor, MI

Quote:

> Can someone give me some help with the following program? I'm entering
> it into Visual C++ 1.0 on Windows 95 just like my C++ tutorial book
> says, and it's not recognizing the getche() function. I've also tried
> _getche(), and that's not recognized either. Please, if possible,
> respond through e-mail, but I will check posts here if it's too much of
> a hassle for you.

> // game1.cpp
> #include <iostream.h>
> #include <conio.h>              // for _getche()

> void main()
> {
>         char dir = 'a';
>         int x = 10, y = 10;
>         cout << "Type Enter to quit\n";
>         while (dir != '\r')                             // until Enter is typed
>         {
>                 cout << "\nYour location is " << x << ", " << y
>                          << "\nPress direction key (n, s, e, w): ";
>                 dir = _getche();                        // get character
>                 if (dir == 'n')                         // go north
>                         y--;
>                 else if (dir == 's')            // go south
>                         y++;
>                 else if (dir == 'e')            // go east
>                         x++;
>                 else if (dir == 'w')            // go west
>                         x--;
>         }       // end while
> }



Sat, 16 Oct 1999 03:00:00 GMT  
 *beginner help needed* getche() function

Quote:

> Can someone give me some help with the following program? I'm entering
> it into Visual C++ 1.0 on Windows 95 just like my C++ tutorial book
> says, and it's not recognizing the getche() function. I've also tried
> _getche(), and that's not recognized either. Please, if possible,
> respond through e-mail, but I will check posts here if it's too much of
> a hassle for you.

> // game1.cpp
> #include <iostream.h>
> #include <conio.h>              // for _getche()

> void main()
> {
>         char dir = 'a';
>         int x = 10, y = 10;
>         cout << "Type Enter to quit\n";
>         while (dir != '\r')                             // until Enter is typed
>         {
>                 cout << "\nYour location is " << x << ", " << y
>                          << "\nPress direction key (n, s, e, w): ";
>                 dir = _getche();                        // get character
>                 if (dir == 'n')                         // go north
>                         y--;
>                 else if (dir == 's')            // go south
>                         y++;
>                 else if (dir == 'e')            // go east
>                         x++;
>                 else if (dir == 'w')            // go west
>                         x--;
>         }       // end while
> }

Evan,
I'm guessing that you have created a Windows program, not a DOS program
in VC++. Unfortunately, _getche() is not available for Windows programs.
(I used VC++ 1.52 to check this out.)

If you look in conio.h you'll find that the declaration of _getche() is
enclosed in a
#ifndef _WINDOWS
#endif
block.
--
Stephen Goodney
All thoughts and opinions are mine alone.



Sat, 16 Oct 1999 03:00:00 GMT  
 *beginner help needed* getche() function

Quote:

> > Evan,
> > I'm guessing that you have created a Windows program, not a DOS program
> > in VC++. Unfortunately, _getche() is not available for Windows programs.
> > (I used VC++ 1.52 to check this out.)

> > If you look in conio.h you'll find that the declaration of _getche() is
> > enclosed in a
> > #ifndef _WINDOWS
> > #endif
> > block.

> So is there anything I can do about this?

> - Kid Fab

Evan,

Yes, it is now clear.  Create a new project and select DOS rather than
windows as your project type.  Move your files to your new project
directory and add them to the project.  Rebuild the project.  If you
need more help doing this, just ask and I'll try to fake it.

Ron



Sat, 16 Oct 1999 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Beginner needs function help

2. Beginner needs function help

3. getche UNIX alternative and function parameter help required!

4. C-beginner needs advise for string function

5. Need DEC C/Borland equivalent of getche()

6. library function to replace getche() in UNIX

7. Equivalent for getche() function in UNIX C?

8. Need beginner help in c

9. Help needed by beginner!

10. Beginner needs help

11. a.) need help for beginner

12. Beginner need help to understand this.

 

 
Powered by phpBB® Forum Software