getch & getche not in ubuntu

Hi I tried executing a C rogram with getch or getche functions in my linux termibal @ ubuntu I used gcc compiler.

On compiling the code, it throws error as below. However, I included <stdio,h> and <stdlib.h> in my source code.

ganesh@ubuntu:~/my_programs/c/letusc/chap11$ gcc -o gb gb.c
/tmp/cc5aNZWD.o: In function `main':
gb.c:(.text+0x7a): undefined reference to `getch'
gb.c:(.text+0x9b): undefined reference to `getch'
collect2: ld returned 1 exit status

Ca any one please help me on this?

Thanks,
Ramkrix

Under Linux, getch() is declered under curses.h and defined with its coressponding ncurses library.

If you still have problems, please revert with your program source.

I tried including the line # include <curses.h> in my source code. It said it cannot find any fileby this name. Then I executed the below "find" command to know the whereabouts of curses.h file. But there is none directly in this name.. please help me on this

ganesh@ubuntu:~/my_programs/c/letusc/chap11$ find / -name "*curse*" -print 2>/dev/null
/usr/lib/python2.6/lib-dynload/_curses.so
/usr/lib/python2.6/lib-dynload/_curses_panel.so
/usr/lib/python2.6/curses
/usr/lib/vlc/gui/libncurses_plugin.so
/usr/bin/ncursesw5-config
/usr/bin/ncurses5-config
/usr/share/doc/lib32ncurses5
/usr/share/doc/libncurses5
/usr/share/doc/ncurses-bin
/usr/share/doc/ncurses-base
/usr/share/doc/libncursesw5
/var/lib/dpkg/info/ncurses-base.preinst
/var/lib/dpkg/info/libncursesw5.list
/var/lib/dpkg/info/libncurses5.list
/var/lib/dpkg/info/ncurses-bin.preinst
/var/lib/dpkg/info/libncursesw5.postinst
/var/lib/dpkg/info/libncursesw5.md5sums
/var/lib/dpkg/info/libncursesw5.shlibs
/var/lib/dpkg/info/lib32ncurses5.md5sums
/var/lib/dpkg/info/ncurses-bin.md5sums
/var/lib/dpkg/info/libncurses5.postrm
/var/lib/dpkg/info/ncurses-base.conffiles
/var/lib/dpkg/info/lib32ncurses5.postrm
/var/lib/dpkg/info/ncurses-base.list
/var/lib/dpkg/info/libncursesw5.postrm
/var/lib/dpkg/info/lib32ncurses5.shlibs
/var/lib/dpkg/info/lib32ncurses5.postinst
/var/lib/dpkg/info/ncurses-bin.list
/var/lib/dpkg/info/libncurses5.postinst
/var/lib/dpkg/info/libncurses5.md5sums
/var/lib/dpkg/info/lib32ncurses5.list
/var/lib/dpkg/info/ncurses-base.md5sums
/var/lib/dpkg/info/libncurses5.shlibs
/lib/libncursesw.so.5
/lib/libncurses.so.5.7
/lib/libncurses.so.5
/lib/libncursesw.so.5.7
/lib32/libncurses.so.5.7
/lib32/libncurses.so.5
ganesh@ubuntu:~/my_programs/c/letusc/chap11$ 

Thanks,
Ramkrix

Which you may want to use under Linux is declered as (under stdio.h header)

extern int getchar (void);

and defined with the '/usr/lib/libc.a' which is the stdio library.

I guess, you are looking for this one and the same is available as getch(), under windows (probably TC?) and described in 'Let us C' because they have tested their program under windows C compiler only.

Apart getc() is same as getchar(stdin) under the same library, I mentioned above.

extern int getc (FILE *__stream);

I could, however, see the libncurses.so in your systems output.

getch() is an ancient DOS syscall from even older versions of Borland Turbo C. Mostly nothing has it these days.

You probably need to install the headers to use curses. It's a package something like curses-dev. There's trillions of them, one for each library, with extremely hard-to-guess names. ubuntu is not a good programming distribution.

No hesitation in admitting that I never knew that getch() is a system call under DOS :slight_smile: , probably may be because I worked very little time on DOS machines, in my initial days (at school) :wink: however did a very good & satisfying amount of programming in pascal using Borland's pascal compiler under DOS / win97 systems.

Now a natural question, I'd ask is why getch() is declared under TurboC's stdio.h header, if that's going to be substituted by a sys routine and not the standard library function?

I'm pretty sure it's in conio.h.

So all that are declered under conio.h are system calls of DOS? I had an initial thought that conio.h is for console I/O kind of stuffs; ya getch() is declered there only.

Is getch() really a system call in DOS?

Cause I could not find the name of that syscall in my ancient DOS manuals; Are you referring to the C function from stdlib?... Not that it matters but I just want to know. :smiley:

I don't mean that getch is literally a dos system call, just that it depends on one. conio.h is a library of routines for using the DOS console.

IBM's PC-DOS or Microsoft MS-DOS? Because it matters ... :smiley: . Just kidding.

---------- Post updated at 10:22 PM ---------- Previous update was at 10:20 PM ----------

Now a serious request; if you could post a soft copy of the same, it will help a lot.

Not sure I understand; you want a copy of MSDOS? bootdisk.com

If any is available in soft copies which is distributable legally. I thought that it'll help a lot , if something like that is handy with this thread :slight_smile:

---------- Post updated at 10:45 AM ---------- Previous update was at 10:36 AM ----------

bootdisk.com , A great site for simple PC trouble-shooting tools / utilities .