getch & getche not in ubuntu


 
Thread Tools Search this Thread
Top Forums Programming getch & getche not in ubuntu
# 1  
Old 06-12-2010
Question 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.


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

Last edited by pludi; 06-12-2010 at 12:48 PM..
# 2  
Old 06-12-2010
use getchar() available under std io library ...

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.
# 3  
Old 06-12-2010
PHP

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


Code:
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

Last edited by pludi; 06-12-2010 at 12:49 PM..
# 4  
Old 06-13-2010
The version of getch() ...

Which you may want to use under Linux is declered as (under stdio.h header)
Code:
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.

Code:
extern int getc (FILE *__stream);

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

Last edited by Praveen_218; 06-14-2010 at 12:49 AM..
# 5  
Old 06-13-2010
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.
# 6  
Old 06-14-2010
Great information for me about DOS ...

Quote:
Originally Posted by Corona688
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 Smilie , probably may be because I worked very little time on DOS machines, in my initial days (at school) Smilie 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?
# 7  
Old 06-14-2010
Quote:
Originally Posted by Praveen_218
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SFTP Shell Script Get & Delete && Upload & Delete

Hi All, Do you have any sample script, - auto get file from SFTP remote server and delete file in remove server after downloaded. - only download specify filename - auto upload file from local to SFTP remote server and delete local folder file after uploaded - only upload specify filename ... (3 Replies)
Discussion started by: weesiong
3 Replies

2. Shell Programming and Scripting

Replace & sign to &amp word

Hi, I have text file abc.txt. In this file, I have the following data. Input: Mr Smith &amp Mrs Smith Mr Smith &apos Mrs Smith Mr Smith & Mrs Smith Mr Smith& Mrs Smith Mr Smith &Mrs Smith Output: Mr Smith &amp Mrs Smith Mr Smith &apos Mrs Smith Mr Smith &amp Mrs Smith Mr Smith&amp... (4 Replies)
Discussion started by: naveed
4 Replies

3. Ubuntu

[UBUNTU] mount.nfs fails in Ubuntu / Works on Red Hat!!!

Gurus, I want log in locally to my Lucid (10.04) workstation and have my code saved over the network on my samba account At work, all developers have samba user ids and when we were running Red Hat, we went thru the following procedure to get setup. * open a shell session to NFS server... (2 Replies)
Discussion started by: alan
2 Replies

4. Shell Programming and Scripting

replace & with &amp; xml file

Hello All I have a xml file with many sets of records like this <mytag>mydata</mytag> <tag2>data&</tag2> also same file can be like this <mytag>mydata</mytag> <tag2>data&</tag2> <tag3>data2&amp;data3</tag3> Now i can grep & and replace with &amp; for whole file but it will replace all... (4 Replies)
Discussion started by: lokaish23
4 Replies

5. Ubuntu

Ubuntu / Ubuntu File Manager / Config

I am using Ubuntu 9.10 with Gnome 2.28. I use the default Nautilus File Manager to view / manage files. Is there a way to add icons or customize the icons that are above the location bar and below the menus? There is a bar that has icons for "Back" "Forward" "Parent" above the location bar. I... (6 Replies)
Discussion started by: drewk
6 Replies

6. Shell Programming and Scripting

PHP read large string & split in multidimensional arrays & assign fieldnames & write into MYSQL

Hi, I hope the title does not scare people to look into this thread but it describes roughly what I'm trying to do. I need a solution in PHP. I'm a programming beginner, so it might be that the approach to solve this, might be easier to solve with an other approach of someone else, so if you... (0 Replies)
Discussion started by: lowmaster
0 Replies

7. UNIX for Dummies Questions & Answers

Would like to install x86 desktop Ubuntu over AMD64 Ubuntu server

My intention was to build a dual boot XP Pro 64 and Ubuntu media server. I had installed the AMD64 version of Ubuntu 8.10 server and thought that I would be able to install Apache server. I need a GUI to work in. I tried to boot and install Mythbuntu 32 bit 8.10, but my machine now won't recognize... (0 Replies)
Discussion started by: docflyboy
0 Replies
Login or Register to Ask a Question