Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Xcode 2.1 and C getch()

Xcode 2.1 and C getch()
Thread Tools
viruscool
Forum Regular
Join Date: Sep 2003
Location: Chester, UK
Status: Offline
Reply With Quote
Nov 11, 2005, 07:06 AM
 
Basically I'm learning to program in C on a windows computer (using visual basic compiler) everything going fine, that was until I cam home and tried to run my code in Xcode, everything runs fine except for the getch() command.
Anyone know of an aternative to getch(), or how to get it to work I.E. which header file etc.

I've looked at this thread here http://forums.macnn.com/showthread.p...ht=getch%28%29 but can't figure out what I'm doing wrong, plus that was back in 2001 and Xcode may have changed quite a bit since then.

Thanks in advance

Viruscool
(The dark lord has risen again......Beware)
     
Thinine
Mac Elite
Join Date: Jul 2002
Status: Offline
Reply With Quote
Nov 11, 2005, 05:23 PM
 
Are you including stdio.h?
     
smitty825
Forum Regular
Join Date: Sep 2003
Location: San Diego
Status: Offline
Reply With Quote
Nov 12, 2005, 12:57 AM
 
viruscool...getch isn't in the C standard library. IIRC, it is a Borland specific addition that was eventually incorporated into the Visual C/C++ compilers.

Anyway, you have a few choices:

1. Substitute the getch() function with the getchar() function. They behave a bit different, though, so you may need to modify your program to handle the differences, though. (I would give a quick code example, but I don't remember exactly how getch() behaves!)

2 Include the "<curses.h>" library. Inside <curses.h>, there is a getch() function that I think behaves the same as the Windows specific version. Including this file will likely make your final application slightly bigger, but the <curses.h> library is fairly portable among platforms and should compile just about anywhere... (There is a free (as in speech) version of the curses library called "ncurses" and implemented by the Free Software Foundation, if you prefer GPL'd stuff)
     
parallax
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status: Offline
Reply With Quote
Nov 24, 2005, 02:34 AM
 
I think you need to do a whole lot of initialization stuff to get the curses routines to run...

I'd switch to getchar(). getc(stdin) works as well.
"Against stupidity, the gods themselves contend in vain" (Schiller)
     
   
 
Forum Links
Forum 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 On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 02:42 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,