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
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
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 , probably may be because I worked very little time on DOS machines, in my initial days (at school) 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?
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.
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.