Help In C

David Sugar david.sugar at canonical.com
Sun Jul 5 21:55:13 BST 2009


getch() is neither part of the ansi C standard library, nor part of
glibc.  It is a Microsoft specific C library function that, at least
originally for DOS applications, used an old DOS INT 21 function to
directly read the keyboard device.  There is a distantly related getch()
function in ncurses that may do something roughly similar, but you would
need to #include <curses.h> and link with -lncurses, and it may not
behave the same.  The ansi C library function you may want to use
instead is getchar().  In both cases, though, these are based on using a
generic stdin stream the process is attached to when it is executed
rather than a "keyboard device".

In the case of ncurses getch(), the keys are extracted from stdin based
on the current TERM mapping and hence multiple byte sequences for
function and arrow keys are decoded and returned as a single key input,
hence this behavior is perhaps most similar to what Microsoft's getch()
does.  In the case of standard C getchar(), only one character byte is
retrieved at a time from stdin in all cases, so for example a function
or arrow key will appear as multiple inputs.

supravat paul wrote:
> Hello every one I'm using Ubuntu 9.04 Linux.... I'm facing some problem
> while compiling my C program:::
> 
> 
> *#include<stdio.h>*
> 
> *#include<stdlib.h>*
> 
> *#include<string.h>*
> 
> 
> *int* main (*int* argc,*char* *argv[]) /* Main function */
> 
> {
> 
> *    char* cont;
> 
> *    printf*("Want to enter new text? y/n: ");
> 
>     cont=*getch();*
> 
> *    if*(cont=='y')
> 
>     {
> 
> *        printf*("Enter text for %s",argv[1]);
> 
>     }
> 
> *    return* EXIT_SUCCESS;
> 
> }
> 
> 
> while compiling this code with the help of following command
> $gcc -o q2 q2.c
> it gives me the following error...
> 
> supravat at supravat-desktop:~/c/Done$ gcc -o q2 q2.c
> /tmp/cc07EFXt.o: In function `main':
> q2.c:(.text+0x42): undefined reference to `getch'
> collect2: ld returned 1 exit status
> 
> This code runs successfully in Windows.... Please help me...
> 
> 
> 
> ------------------------------------------------------------------------
> Love Cricket? Check out live scores, photos, video highlights and more.
> Click here
> <http://in.rd.yahoo.com/tagline_cricket_2/*http://cricket.yahoo.com>.
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: david_sugar.vcf
Type: text/x-vcard
Size: 241 bytes
Desc: not available
Url : https://lists.ubuntu.com/archives/ubuntu-motu-mentors/attachments/20090705/0e2eff46/attachment.vcf 


More information about the Ubuntu-motu-mentors mailing list