Click to See Complete Forum and Search --> : help with getch()


vhg119
07-03-2002, 09:54 PM
i included curses.h as well as stdlib.h and stdio.h in my lil program

the main function only contains 3 lines

int number;
number = getch();
printf( "you typed %c", number);


when i compile this, gcc gives me some errors:
cursestest.c:9: undefined reference to 'stdscr'
cursestest.c:9: undefined reference to 'wgetch"

what is the problem?

binaryDigit
07-03-2002, 10:39 PM
did you compile with -lncurses?

gcc program.c -lncurses

Energon
07-03-2002, 10:41 PM
Add -lcurses to your compile line. So something like this:

# gcc -Wall -c cursestest.c
# gcc -o my_program -lcurses

That'll make it link to the curses libraries. You may need to specify where those libraries are at if it doesn't work, which would look like:

# gcc -o my_program -L/path/to/curses/lib -lcurses

vhg119
07-04-2002, 12:06 AM
doh!
now it gives me:
undefined references to 'main'

vhg119
07-04-2002, 01:37 AM
hey i got it!

i thought i could just use getch() by itself. But i needed to create a WINDOW type pointer and initiating a window and everything... kinda like gtk programming i guest.

thanks guys.. that gcc argument thing helped too. :D

binaryDigit
07-04-2002, 10:34 AM
there are some ncurses examples at:
CCAE (http://www.codeexamples.org)

sans-hubris
07-04-2002, 02:31 PM
Check out how to use select. Using ncurses for the functionality of getch is a bit superfluous.

vhg119
07-05-2002, 01:57 AM
select? i'll look into that.
are there any good howto's and documentation? kinda like the gtk+ one on gtk.org?

Strike
07-05-2002, 02:38 PM
man select :)

(yes, it has an example)